如何显示从URL视频视频、URL

2023-09-07 16:15:15 作者:时间已摆平所有犯的错

我有试图通过次活动从URL推出视频我的应用程序的主选项卡上的按钮

I have a button on the main tab of my apps that attempts to launch a video from an URL via second activity

我有一个空白活性测试,并成功地显示你好时,说按钮的点击。然后,我删除了'你好'editext并添加codeS为在另一个类似的帖子建议Java文件。

I have tested with a Blank activity and successfully displayed 'Hello' when the said button is click. I then removed the 'Hello' editext and added codes to the java file as suggested in another similar post.

当点击视频BTN,我得到的消息;不能播放这段视频,确定

When the video btn is clicked, I get the message ;Can't play this video, Ok'

我已经测试了Youtube链接是一个有效的链接。然而logcat的错误消息包括:

I have already tested the youtube link it is a valid link. Yet logcat error message include :

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 do I go from here ?

有第二活性的XML是如下: -     

An XML for the second activity is as follows :-

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

</TableLayout>

相应的Java文件

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的

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

推荐答案

试试这个:

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 it will work, but worth a try