views:

2428

answers:

5

I am writing an application to play youtube videos using streaming.

First method:

I am getting the RTSP URL to the video using GData APIs. Here is the code to play the RTSP url.

   VideoView mVideoView = new VideoView(this);
   setContentView(mVideoView);
   mVideoView.setVideoURI(Uri.parse("rtsp://rtsp2.youtube.com/CiILENy73wIaGQkDwpjrUxOWQBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
   mVideoView.start();

But it throws error on both G1 device and emulator (Emulator has some firewall problem as per mailing list) Here is the error message

ERROR/PlayerDriver(35): Command PLAYER_INIT completed with an error or info PVMFFailure

Second method:

A hack way to get the path of 3gp file from http://www.youtube.com/get_video?v=&t=<>&<>.. After getting the file path and I can call setVideoURI and it plays fine. But it is a hack way to achieve the requirement. I have checked the Youtube App also, it also does the hack way to play the youtube url.(Checked with logcat)

I have tried changing from VideoView to MediaPlayer but no change in the error.

Is there a "Clean" way to do this?

Please let me know your thoughts.

A: 

I'm impressed that the dirty way works at all! If you've got a working solution, go with it. I don't think there's a clean way to get RTSP streaming working in the SDK yet.

haseman
+1  A: 

Can't you just invoke the YouTube player to play the video? (similar to how the iPhone YouTube app works?)

Geoff
+1  A: 

If you're willing to do the work in a new activity, the following will work on a device but not on the emulator:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));

Mike
This works on device because it has youtube app installed. I don't want my application to depend on Youtube App
Vinay
A: 

I'm having the same problem on 1.6, here's my logcat:

V/VideoView( 1074): reset duration to -1 in openVideo
D/MediaPlayer( 1074): Couldn't open file on client side, trying server side
W/PlayerDriver(  542): Using generic video MIO
E/SW_DEC  (  542): PV SW DECODER is used for H.263
D/PlayerDriver(  542): buffering (0)
D/PlayerDriver(  542): buffering (0)
D/PlayerDriver(  542): buffering (0)
D/PlayerDriver(  542): buffering (0)
D/PlayerDriver(  542): buffering (0)

And it keeps buffering (0) to infinity and beyond, not actually playing anything. I won't like it, but I'll have to go the dirty way.

Felix
A: 

sometimes Uri.parse return "null" because cant parse an rtsp protocol instead of http protocol.

Look it with an Log in logcat Uri.parse(rtspURL).toString() and you will see nothing writed. or only make Log.d("tag", Uri.parse); and the same will be return.

Try to find another way to parse (create) an Uri.

Id try with that and run:

////////////

String urlVideo = VideoView video = (VideoView)findViewById(R.id.VideoView01); Log.d(tag , urlVideo); video.setVideoURI(Uri.parse(urlVideo)); MediaController mc = new MediaController(this); video.setMediaController(mc); video.requestFocus(); video.start(); mc.show();

///////////

XanXa