Android HLS Streaming - Different Android Versions Load Different Location in Stream

HaemEternal picture HaemEternal · May 29, 2013 · Viewed 23.2k times · Source

I realise that there are some issues in terms of level of support of HLS in Android. I'm trying to write a small videoplayer demo (to work on as many devices as possible); preferably without using a third party library; that can stream HLS video.

NOTE: I'm currently testing on JellyBean 4.2.2, but have access to other versions

I have managed to use the MediaPlayer class so that my app is able to start playing a stream (eg Apple's test video BipBopAll), but it seems to be loading the wrong section of the stream, as the video seems to start at 29 minutes in (and so it finishes after about thirty seconds).

The code that I've used is pretty basic:

private void playTrack()
{   
    player = new MediaPlayer();

    try 
    {                   
        player.setDisplay(holder);
        player.setDataSource("http://devimages.apple.com/iphone/samples/bipbop
                              /bipbopall.m3u8");
        player.prepare();

    } 
    catch (...) 
    {
    }
    player.start();
}

Update: I've tested the same code on ICS 4.0.4, and it works correctly. Testing in 3.0.1, loads the stream at 15 minutes, and then runs correctly from there.

What can I do to ensure that the stream starts at the beginning, and plays correctly on multiple Android versions?

Or, is there a better implementation that I should use?

Answer

HaemEternal picture HaemEternal · Jun 14, 2013

Following some further investigation, I've found the following information that can hopefully help other people get HLS streaming on Android working.

Encoding - The video encoding, and the segmentation setup can have a large impact on the Android versions that the video supports. I ended up creating a video using HandBrake, with the following settings:

  • MP4 File
  • H.264; Baseline Profile; Level 3
  • AAC Audio; 44.1k; 128bit (Note: I found that JellyBean was a lot more picky about the audio than ICS/Honeycomb. Some audio bitrates would create videos that Jellybean would not play at all. In general Mono and low bitrate audio seemed to work better on Jellybean).

Segmentation - Using the Apple MediaFileSegmenter, I found adding the "-no-floating-point-duration" and "-z none" flags allowed me to create a video that worked across Android 3.0->4.2

Gingerbread - I was unable to get Android 2.3 to work with HLS out of the box, but I did find that using the Vitamio library worked pretty well (see this question for further info)