在视频方面,我的想法很少。尽管如此,我正在构建一个需要以下功能的应用程序:给定视频的网址,播放视频。这个看似简单的任务对我来说非常困难。这是我的代码:
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(); } }
这是我得到的错误:
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)
有趣的是,我可以看到控件在VideoView的底部发短时间。但是没有视频播放,VideoView背景就是这样。有谁知道我怎么解决这个问题?
除了
否则是否有已知的库可以做到这一点?理想情况下,我希望能够使用YouTube视频链接或任何其他视频链接。我看过ExoPlayer和Protyposis但是它们都有超出我想象的文字/概念;名为二的话,如TrackRenderer和ChunkSampleSource。此外,Youtube API本身似乎有一些问题要求:设备必须安装Youtube应用程序,我必须提供videoId而不是视频网址。 (我没有看得太深,看看是否可以从网址解析videoId。)
注
我用Youtube视频链接和非Youtube视频链接试过这个。对于Youtube链接,我右键单击视频本身以获取链接。
答案 0 :(得分:1)
有谁知道我怎么解决这个问题?
为one of the supported media formats and served via one of the supported protocols中的视频提供Uri
,而不是Uri
到网页。 https://www.youtube.com/watch?feature=player_detailpage&v=c4rSDxwHJI0是一个网页。