is there a way to play streaming youtube video fro

2019-01-29 09:49发布

Somewhere in my Android app I would like to play a youtube video, in my activity, in a small view. I'm trying to do this using VideoView, but no luck so far..

I wrote a simple activity, here is my code so far:

public class MainView extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    VideoView videoView = (VideoView) findViewById(R.id.VideoView);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    /*working good but IT'S NOT youtube*/ //Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp"); 
    /*NOT WORKING*/ //Uri video = Uri.parse("http://www.youtube.com/watch?v=hLQl3WQQoQ0&ob=av2e");
    /*NOT WORKING (RTSP)*/ //Uri video = U-ri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&feature=grec_mobile&v=6WHRxXY67UA");
    /*NOT WORKING (RTSP)*/Uri video = Uri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&v=wWub_aXPCVg");
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);
    videoView.start();
   }
}

is it possible? is there any other SDK component that can do that? any ideas?

Thanks, Amitos80

3条回答
Lonely孤独者°
2楼-- · 2019-01-29 09:58

If you know what video you want to view, you could just create an Intent with the url in it and use that to launch the Youtube app. You can see this SO Post for more details.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-29 10:02

Google are releasing android components for YouTube "in the coming months", so hopefully by the end of 2012.

What I am doing in the meantime is using a WebView with loadData(), and passing in an IFrame as stated on the YoUTube API page. The Iframe is quite limited (most parameters don't even work, like controls=0), so if you need more flexibility like controlling the view then use the JavaScript API and then embed the JavaScript in the HTMl you pass into loadData.

I tried the Media Controller and couldn't get it to work, even though YouTube use it in there own app.

The other thing to try which i didn't get around to. Is to use the google search apis. You can specify a YouTube video and it will give you the URL's to the thumbnails, videos etc. This way you can get to the raw files (www.youtube.com/...../..../myfile.3gp) rather than calling a webpage. These might then be loadable in the MediaController.

查看更多
forever°为你锁心
4楼-- · 2019-01-29 10:13

you can simply use youtube rtsp link in videoview as:

    String myurl="rtsp://v4.cache4.c.youtube.com/CjYLENy73wIaLQk_ezfHQ9mvqRMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYN-__7O28NSPUAw=/0/0/0/video.3gp";     

        Uri video = Uri.parse(myurl);
        mVideoView = new VideoView(this);           
        mVideoView.setVideoURI(video);
        myMediaController = new MediaController(this);

it works simply for me.

查看更多
登录 后发表回答