Media player using YouTube?
Asked Answered
S

3

7

I am developing a sample application using MediaPlayer.By using the raw resources folder,the video can be played.But I want to play through URL.How can I achieve this?

My code is:

VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        // Set video link (mp4 format )
        Uri video = Uri.parse("http://www.youtube.com/watch?v=T1Wgp3mLa_E");
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
Spavin answered 16/11, 2011 at 8:15 Comment(1)
Q-GLuydiMe4 id will not open through this way ? is this happen with you or not. Plaese let me knoe ?Dak
S
4

You need to get the correct streaming(rtsp) url rather than the link to the player page you are using. You can get this programmatically using the google data api

Once you have done that you would simply replace

"http://www.youtube.com/watch?v=T1Wgp3mLa_E" with "rtsp://v8.cache1.c.youtube.com/CiILENy73wIaGQnxa4t5p6BVTxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"

in your existing code and it should work.

Note: The quality of video, when streaming to your own videoview, can be very poor compared to how it looks when played on the youtube site or player app.

Spectrochemistry answered 16/11, 2011 at 8:52 Comment(2)
can u expand me the answer, what i should do with google data api, i was bit confused..Spavin
Q-GLuydiMe4 id will not open through this way ?Dak
M
2

You have to rtsp links from gdata api :gdata api with this: http://gdata.youtube.com/feeds/api/videos?&max-results=20&v=2&format=1&q="+ URLEncoder.encode(activity.criteria)

Element rsp = (Element)entry.getElementsByTagName("media:content").item(1);

                              String anotherurl=rsp.getAttribute("url");

In gdata api only we are getting this type of links : rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

These are playing in VideoView.

My answer link :RTSP Links

Monaco answered 16/11, 2011 at 9:23 Comment(1)
Q-GLuydiMe4 id will not open through this way ? have you aware why is it not playing ?Dak
H
1

In order to get better quality videos, I checked what these guys did. It helped me very very much!

I'm posting the link so you can checkout their project and use their code.

Herculean answered 13/1, 2012 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.