I'm working on a music APP that displays lyrics and info about songs and also plays songs from a youtube URL.
In my activity, there are some TextViews (for the lyrics/info) and one VideoView (for the youtube link).
I've created a class called YoutubeVideo, that does the following:
- Downloads the content of this page: http://gdata.youtube.com/feeds/api/videos?q=SONG_NAME&v=2&max-results=1, parses it's content and gets the youtube's id (e.g EvuL5jyCHOw). This is a RSS feeds page that searches for videos and display 1 result (And all I need to do is to change the query).
- Downloads the content of this page: http://gdata.youtube.com/feeds/api/videos?q=YOUTUBES_ID&format=1&alt=json, parses it's content and gets the rtsp (e.g rtsp://v7.cache3...3gp). This is an XML file that holds some information about the video (name, length, thumbnail and of course - rtsp link :).
- Than all I need to do is to set the rtsp as VideoURI:
VideoView.setVideoURI(Uri.parse(rtsp))
and the video is being played.
If you wonder, I use this class like that: new YoutubeVideo(VideoView).setVideo(artist + " " + title);
It works, but I got one problem: It's a 3gp file... Which has really bad quality. How can I get better quality urls? (mp4/flv/ect?)