28

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.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Vinay
  • 4,743
  • 7
  • 33
  • 43
  • 1
    Could you maybe explain the hack a little bit more? I'm facing the same problem. – Janusz Apr 15 '12 at 17:17
  • Can't you just invoke the YouTube player to play the video? (similar to how the iPhone YouTube app works?) – Geoff Aug 12 '09 at 03:45
  • Have a look also to [How to get thumbnail of YouTube video link using YouTube API?](http://stackoverflow.com/q/2068344/995926) There is a smart answer which points how to get the rtsp url: Try this one as an example: http://gdata.youtube.com/feeds/api/videos/gzDS-Kfd5XQ?v=2&prettyprint=true&alt=json – rekire Nov 22 '12 at 07:18
  • if you find the solution, please share it. – PiyushMishra Dec 10 '12 at 06:09

8 Answers8

2

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")));

emmby
  • 99,783
  • 65
  • 191
  • 249
  • 4
    This works on device because it has youtube app installed. I don't want my application to depend on Youtube App – Vinay Aug 22 '09 at 13:00
  • is there any other way to play youtube video without youtube app or device doesn't support flash and html5. – Hiren Dabhi Feb 28 '12 at 05:26
2

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 written. or only make Log.d("tag", Uri.parse); and the same will be return.

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

I'd try with that and run:

String urlVideo = <your rtspURL>
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();
Pratik
  • 30,639
  • 18
  • 84
  • 159
XanXa
  • 21
  • 2
1

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
  • 11,213
  • 8
  • 41
  • 38
1

we faced a very similar problem.

At the moment I'm at the first step of my project and I'm trying to make the videoview simply works. I'm taking data from here: http://gdata.youtube.com/demo/ and I'm testing all the videos links.

RTSP 3GP videos are really really really low quality video.... and there is no way to access to mp4 (good quality) videos. I really don't know how to make it works because I think that MP4 streams are available only to premium devs....

StErMi
  • 5,389
  • 5
  • 48
  • 71
1

Throw eye over Youtube API

I think this also use youtube app(Which you don't want)

But just refer may be you will find some key to solve it

edwin
  • 7,985
  • 10
  • 51
  • 82
0

The header on the video indicates it does work for Android. So, try a good video link to experiment with. Here is one that I use:

rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov

I works great on Nexus and Samsung tablets.

Droid Chris
  • 3,455
  • 28
  • 31
0

do you have the access to the internet? if not, please add the Internet permission to the manifest file

 <uses-permission android:name="android.permission.INTERNET" />

and also please try these URIs:

rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov

http://www.wowza.com/_h264/BigBuckBunny_175k.mov
Albert Chen
  • 1,331
  • 1
  • 12
  • 13
0

I've displayed YouTube videos with the following code. I hope its useful, but let me know how it might be improved.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    startActivity(new Intent(Intent.ACTION_VIEW, 
                  Uri.parse("http://www.youtube.com/watch?v=...")));
}

public void onPrepared(MediaPlayer mp) {
     // TODO Auto-generated method stub
}
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
reaper
  • 17
  • 3