7

I would like to play a http live steaming link(.m3u8) on android. Can you please let me know how to write code for that (snippet)?

I tried the following(on Activity's onCreate event) but it wouldnt work (says Cant play video) :

VideoView vv = new VideoView(this);
Uri uri =Uri.parse("http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8");
vv.setVideoURI(uri);
setContentView(vv);

note: using emulator for testing thanks for the help

Reno
  • 33,594
  • 11
  • 89
  • 102
Jay
  • 77
  • 1
  • 1
  • 6
  • AFAIK, the WIFI network layer on Emulator is sort of mocked from underlying operating system network layer, if your computer sit behind some Proxy server, you will probably get similar kind of error (If I recall, I used to get similar kind of error). – yorkw Nov 26 '11 at 10:25
  • Did you call vv.start() after setting the ContentView? This should work. Is there any exception you get? – Rajdeep Dua Nov 02 '11 at 10:28
  • hi rajdeep, just added vv.start() but doesnt help - same output. LogCat shows a couple of messages: Error message: "Unable to create media player" . and the exception is java.io.IOException : setDataSource failed. – Jay Nov 02 '11 at 11:37

2 Answers2

3

Try the following :

    String httpLiveUrl = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8";
    videoView.setVideoURI(Uri.parse(httpLiveUrl));
    videoView.setMediaController(new MediaController(this));
    videoView.requestFocus();
    videoView.start();

OR

Try using the VitaMio media player

HTTP live streaming (M3U8), for Android 2.1+

edit: The VitaMio player is dead


I think this will work just fine in the actual device, since it works in HoneyComb, the emulator can be broken sometimes

Reno
  • 33,594
  • 11
  • 89
  • 102
  • thanks Reno, But I came to know that android 3+ have default support for http live streaming(HLS). Since I will be developing only for android 4, is VitaMio required ? – Jay Nov 02 '11 at 10:20
  • 1
    There are [some known issues](http://code.google.com/p/android/issues/detail?id=17118) with it. The emulator is not reliable it seems. – Reno Nov 02 '11 at 10:28
  • reno, it doesnt seem to work. What I did was : In the Acitivity's onCreate function I added - VideoView videoView = new VideoView(this);;setContentView(videoView); - When i run this I get following in logCat: 1. D - MediaPlayer - Couldnt open files on client side, trying server side 2. E - MediaPlayer - error(1, -2147483648) and two other line with same error messages as second one. On the emulator the output is "Cant play video" dialog. – Jay Nov 02 '11 at 12:04
  • +1 This is the correct way to do it on Emulator, I am using same piece of code in two of my Android projects without any problem. Note, for some real device, httplive doesn't work, need change it back to http. – yorkw Nov 26 '11 at 10:15
  • 1
    the `httplive` scheme is not supported. – Roman Nurik Jan 05 '12 at 02:33
  • Reno is there any other way to play m3u8 file with out using Third party library – Abhi Jan 27 '12 at 09:37
  • Did anyone get this working? I get the same prob as @Jay on Anroid 4.0.3. – BlueVoodoo Jun 11 '12 at 12:07
1

Looks like this might not be fully supported in the emulator. This runs fine on a ICS device

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22