Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 869
HaemEternal Avatar asked May 29 '13 09:05

HaemEternal


People also ask

Does HLS support Android?

It is the default media streaming protocol for all iOS devices, but it can be used on Android and web browsers. The basic building blocks of a HLS streams are: M3U8 playlists. Media files for various streams.

Does HLS use TCP or UDP?

Because UDP is faster, some streaming protocols use UDP instead of TCP. HLS, however, uses TCP. This is for several reasons: HLS is over HTTP, and the HTTP protocol is built for use with TCP (with some exceptions).

Is HLS good for streaming?

HLS is highly scalable for delivering live streams and video content across global content delivery networks (CDNs) using ordinary web servers.

Is HLS adaptive?

HTTP Live Streaming (also known as HLS) is an HTTP-based adaptive bitrate streaming communications protocol developed by Apple Inc. and released in 2009. Support for the protocol is widespread in media players, web browsers, mobile devices, and streaming media servers.


1 Answers

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)

like image 145
HaemEternal Avatar answered Nov 15 '22 19:11

HaemEternal