Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

android - Media player using YouTube?

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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...