is there a way to play streaming youtube video from my activity?

前端 未结 3 1921
孤独总比滥情好
孤独总比滥情好 2020-12-22 11:43

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 fa

相关标签:
3条回答
  • 2020-12-22 12:07

    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.

    0 讨论(0)
  • 2020-12-22 12:16

    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.

    0 讨论(0)
  • 2020-12-22 12:20

    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.

    0 讨论(0)
提交回复
热议问题