Search code examples
androidandroid-3.0-honeycombhttp-live-streaming

HLS (http live streaming) on Android 3.0 and seeking


We have a provider that gives us m3u8 files for HLS streams (originally intended for use in an iOS app).

Android 3.0+ supports http live streaming (http://developer.android.com/guide/appendix/media-formats.html) - and we can in fact play these m3u8 files using the standard VideoView on Android 3.0+.

EDIT: Android seems to treat this as "real-time" video feed, and disables the ability to seek or calculate a video duration. (Where-as iOS let's you seek within the stream without issue)

Is there any way to force android 3.0+ to seek within these files?

Here is a sample activity for others to test with:

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class SandboxActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        VideoView vw = (VideoView) findViewById(R.id.videoView);
      vw.setVideoPath("http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8"); 
        vw.setMediaController(new MediaController(this));
        vw.requestFocus();
        vw.start();
    }
}

and a sample layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" android:id="@+id/root">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />
</RelativeLayout>

This is using a sample HLS link from Apple.


Solution

  • Look at this (which you referred too) page

    It says:

    • Protocol version 3 (Android 4.0 and above)
    • Protocol version 2 (Android 3.x)

    And here you can check draft's for HLS. You can choose a version at the top of the page.

    First reference to seeking appeared in draft 3 (comparing to draft 2 Android 3.x)

    The value of the date and time provides an informative mapping of the timeline of the media to an appropriate wall-clock time, which may be used as a basis for seeking

    Just to make sure. I didn't read through whole draft. But, my guess would be that Android implemented quite early draft in Android 3.0 and they may have implemented it partially, which is enough to play, but it's not enough to seek.

    I don't think that you have an easy fix for this, except brining in 3rd party HLS client (as suggested by vipw)