I have minimal knowledge imaginable when it comes to videos. Nonetheless, I am building an app that requires the following functionality: given the url of a video, play the video. This seemingly simple task has proven very difficult for me. Here is my code:
XML:
<VideoView android:id="@+id/videoview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:background="@color/primary_dark"/>
JAVA:
private void setupVideoToPlay(Bundle savedInstanceState,View parent) { mVideoView=(VideoView)parent.findViewById(R.id.videoview);
mMediaController=new MediaController(getContext()); mMediaController.setAnchorView(mVideoView); mVideoView.setMediaController(mMediaController);
mVideoView.setVideoURI(Uri.parse(mVideoUrl));
mVideoView.requestFocus(); if(null != savedInstanceState ) { int position = savedInstanceState.getInt(VIDEO_SEEK_POSITION); mVideoView.seekTo(position); } else { mVideoView.start();
} } And here is the error I am getting:
D/MediaPlayer﹕ setDataSource IOException happend : java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?feature=player_detailpage&v=c4rSDxwHJI0 at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1085) at android.widget.VideoView.openVideo(VideoView.java:370) at android.widget.VideoView.access$2100(VideoView.java:73) at android.widget.VideoView$7.surfaceCreated(VideoView.java:651) at android.view.SurfaceView.updateWindow(SurfaceView.java:606) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:184) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:895) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2158) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1185) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6591) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777) at android.view.Choreographer.doCallbacks(Choreographer.java:590) at android.view.Choreographer.doFrame(Choreographer.java:560) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5837) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) The funny thing is I can see the controls fat the bottom of the VideoView for a brief moment. But there is no video playing and the VideoView background is all that shows. Does anyone know how I might fix this?
Aside
Otherwise are there known libraries out there that can do this? Ideally I want to be able to use youtube video links or any other video links. I have looked at ExoPlayer and Protyposis but both have words/concepts that are way above my head; words such as, TrackRenderer and ChunkSampleSource, to name two. Also, the Youtube API itself seems to have a few problematic requirements: the device must have the Youtube app installed, and I must provide videoId as opposed to url of video. (I haven’t looked deep enough to see if the videoId can be parsed from the url).
NOTE
I have tried this with Youtube video links and non-Youtube video links. And for the Youtube links, I right-click on the video itself to get the link.
http://i.istockimg.com/video_passthrough/63649595/153/63649595.mp4. And since it ends in.mp4, I assume it is a video, not just a website that plays a video.