如何在Android的播放YouTube视频? [英] How to play YouTube video in android?
问题描述
我有一个 VideoView
和我设置YouTube视频的URI和设置 android.permission.INTERNET对
,但我得到了当我要播放的视频这条消息。你不能播放的视频
这code片的视频播放器
mVideoView =(VideoView)findViewById(R.id.skillVideo);
mVideoView.setVideoURI(Uri.parse(http://www.youtube.com/watch?v=1_pryg5HFYY));
mVideoView.setMediaController(新的MediaController(本));
mVideoView.requestFocus();
这是在XML VideoView
布局文件:
....
< VideoView机器人:ID =@ + ID / skillVideo
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =200dp>< / VideoView>
....
在此code这里是我做了什么,我删除了从UI在 MediaControllers ,然后跑到我的YouTube视频流RTSP扔在我的布局有一个基本VideoView我需要的按钮。你可以在实际行动看到这个位置上的Android系统。
Markethttps://market.android.com/details?id=com.sbrecords&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5zYnJlY29yZHMiXQ.. VIDEO_URL = "rtsp://v7.cache3.c.youtube.com/CjgLENy73wIaLwkeUryQ8ZkCqRMYJCAkFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg6KnB9MbH8sVODA==/0/0/0/video.3gp";
尝试{
最后VideoView videoView =(VideoView)findViewById(R.id.videoView1);
// 1 //的MediaController =新的MediaController(Splashscreen.this);
// 2 //mediaController.setAnchorView(videoView);
//设置视频链接(MP4格式)
乌里视频= Uri.parse(VIDEO_URL);
//videoView.setMediaController(mediaController);
videoView.setVideoURI(视频)
videoView.setOn preparedListener(新在preparedListener(){
公共无效于prepared(MediaPlayer的MP){
progressDialog.dismiss();
videoView.start();
}
});
}赶上(例外五){
progressDialog.dismiss();
的System.out.println(视频播放错误:+ e.getMessage());
}
//线程浪费时间,同时显示启动画面
螺纹SplashThread =新的Thread(){
@覆盖
公共无效的run(){
尝试 {
同步(本){
//等待的时间特定时期
等待(7450000);
}
}赶上(InterruptedException的前){
}
完();
I have a VideoView
and I set URI of youtube video and set android.permission.INTERNET
but I got this message when I want to play the video .. "you can't play the video"
this code piece for video player
mVideoView = (VideoView) findViewById(R.id.skillVideo);
mVideoView.setVideoURI(Uri.parse("http://www.youtube.com/watch?v=1_pryg5HFYY"));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
and this is the VideoView
in xml layout file :
....
<VideoView android:id="@+id/skillVideo"
android:layout_width="wrap_content"
android:layout_height="200dp"></VideoView>
....
In this code here is what I have done, I removed the MediaControllers from the UI and ran my youtube video stream threw rtsp and in my layout there is a basic VideoView with my needed button. you can see this in real action here on the Android.
Markethttps://market.android.com/details?id=com.sbrecords&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5zYnJlY29yZHMiXQ.. video_url = "rtsp://v7.cache3.c.youtube.com/CjgLENy73wIaLwkeUryQ8ZkCqRMYJCAkFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg6KnB9MbH8sVODA==/0/0/0/video.3gp";
try {
final VideoView videoView =(VideoView)findViewById(R.id.videoView1);
//1 //mediaController = new MediaController(Splashscreen.this);
//2 //mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
//videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
// Thread to waste time while displaying splash screen
Thread SplashThread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
// Wait given period of time
wait(7450000);
}
} catch (InterruptedException ex) {
}
finish();
这篇关于如何在Android的播放YouTube视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!