How to display video from url

I have a button on the main tab of my applications that tries to start a video from a URL through a second activity

I tested the Blank action and successfully displayed "Hello" when the button is pressed. Then I deleted the "Hello" editext and added the codes to the java file, as suggested in another similar post.

When the btn video is clicked, I get a message: this video cannot be played, Ok '

I already tested the youtube link, this is a valid link. However, the logcat error message includes:

10-07 09:04:36.785: I/MediaPlayer(11397): path is null 10-07 09:04:36.795: D/MediaPlayer(11397): setDataSource IOException happend : 10-07 09:04:36.795: D/MediaPlayer(11397): java.io.FileNotFoundException: No content provider: http://youtu.be/RFrg1xFoxeQ 

Where am I going from here?

The XML for the second action is as follows:

 <VideoView android:id="@+id/videoView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableLayout> 

Corresponding Java File

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_serve_motion_up_together); String videoPath2 = "http://youtu.be/RFrg1xFoxeQ"; VideoView videoView1 = (VideoView) findViewById(R.id.videoView1); videoView1.setVideoURI(Uri.parse(videoPath2)); videoView1.setMediaController(new MediaController(this)); videoView1.setVisibility(1); videoView1.bringToFront(); videoView1.requestFocus(); videoView1.start(); } 

Logcat

 10-07 09:04:36.765: D/dalvikvm(11397): GC_CONCURRENT freed 97K, 12% free 9619K/10887K, paused 13ms+2ms, total 47ms 10-07 09:04:36.785: V/MediaPlayer(11397): constructor 10-07 09:04:36.785: V/MediaPlayer(11397): setListener 10-07 09:04:36.785: I/MediaPlayer(11397): path is null 10-07 09:04:36.795: D/MediaPlayer(11397): setDataSource IOException happend : 10-07 09:04:36.795: D/MediaPlayer(11397): java.io.FileNotFoundException: No content provider: http://youtu.be/RFrg1xFoxeQ 10-07 09:04:36.795: D/MediaPlayer(11397): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:710) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:929) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.widget.VideoView.openVideo(VideoView.java:235) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.widget.VideoView.access$2000(VideoView.java:51) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.widget.VideoView$6.surfaceCreated(VideoView.java:478) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.SurfaceView.updateWindow(SurfaceView.java:591) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.SurfaceView.access$000(SurfaceView.java:81) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:173) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1944) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.Choreographer.doCallbacks(Choreographer.java:555) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.Choreographer.doFrame(Choreographer.java:525) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.os.Handler.handleCallback(Handler.java:615) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.os.Handler.dispatchMessage(Handler.java:92) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.os.Looper.loop(Looper.java:137) 10-07 09:04:36.795: D/MediaPlayer(11397): at android.app.ActivityThread.main(ActivityThread.java:4867) 10-07 09:04:36.795: D/MediaPlayer(11397): at java.lang.reflect.Method.invokeNative(Native Method) 10-07 09:04:36.795: D/MediaPlayer(11397): at java.lang.reflect.Method.invoke(Method.java:511) 10-07 09:04:36.795: D/MediaPlayer(11397): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007) 10-07 09:04:36.795: D/MediaPlayer(11397): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) 10-07 09:04:36.795: D/MediaPlayer(11397): at dalvik.system.NativeStart.main(Native Method) 10-07 09:04:36.795: D/MediaPlayer(11397): Couldn't open file on client side, trying server side 10-07 09:04:36.795: V/MediaPlayer(11397): setVideoSurfaceTexture 10-07 09:04:36.795: V/MediaPlayer(11397): MediaPlayer::setAudioStreamType 10-07 09:04:36.795: V/MediaPlayer(11397): setVideoSurfaceTexture 10-07 09:04:36.795: V/MediaPlayer(11397): prepareAsync 10-07 09:04:36.825: D/ProgressBar(11397): setProgressDrawable mProgressDrawable = null, d = android.graphics.drawable.LayerDrawable@41b6d730needUpdate = false 10-07 09:04:36.825: D/ProgressBar(11397): setProgress = 0 10-07 09:04:36.825: D/ProgressBar(11397): setProgress = 0, fromUser = false 10-07 09:04:36.825: D/ProgressBar(11397): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 100 10-07 09:04:36.835: W/ResourceType(11397): Failure getting entry for 0x010802c9 (t=7 e=713) in package 0 (error -75) 10-07 09:04:36.935: E/SpannableStringBuilder(11397): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 10-07 09:04:36.935: E/SpannableStringBuilder(11397): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 10-07 09:04:40.699: V/MediaPlayer(11397): message received msg=100, ext1=1, ext2=-2147483648 10-07 09:04:40.699: E/MediaPlayer(11397): error (1, -2147483648) 10-07 09:04:40.699: V/MediaPlayer(11397): callback application 10-07 09:04:40.699: V/MediaPlayer(11397): back from callback 10-07 09:04:40.699: E/MediaPlayer(11397): Error (1,-2147483648) 10-07 09:04:40.699: D/VideoView(11397): Error: 1,-2147483648 10-07 09:04:40.719: W/ResourceType(11397): Failure getting entry for 0x010802c9 (t=7 e=713) in package 0 (error -75) 

TIA

Cch4adt

+7
android android-videoview
source share
2 answers

Try the following:

 String LINK = "http://youtu.be/RFrg1xFoxeQ"; setContentView(R.layout.mediaplayer); VideoView videoView = (VideoView) findViewById(R.id.video); MediaController mc = new MediaController(this); mc.setAnchorView(videoView); mc.setMediaPlayer(videoView); Uri video = Uri.parse(LINK); videoView.setMediaController(mc); videoView.setVideoURI(video); videoView.start(); 

I'm not sure if it works, but it's worth a try

+1
source share

You cannot just put the YouTube URL in MediaPlayer. In the end, a link to some kind of web page. Android is trying to handle this, although the ContentProvider for this URL (scheme, domain, etc.) is missing. If you want to play YouTube videos in your application, you should learn the YouTube SDK for Android .

Best regards, Darek

0
source share

All Articles