Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HLS (http live streaming) on Android 3.0 and seeking

Tags:

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.

like image 614
NPike Avatar asked Jun 13 '12 16:06

NPike


People also ask

Does HLS work on Android?

Apple created the HLS standard in 2009, and it is the required streaming format for iOS devices. Since then, Android has added support, as have most other platforms. HLS is popular for a number of reasons. HLS can play almost anywhere.

How do I play HLS stream on Android?

To play an HLS stream, you need to depend on the HLS module. You can then create a MediaItem for an HLS playlist URI and pass it to the player. // Create a player instance. ExoPlayer player = new ExoPlayer.

What is HLS live stream?

Send live and on‐demand audio and video to iPhone, iPad, Mac, Apple Watch, Apple TV, and PC with HTTP Live Streaming (HLS) technology from Apple. Using the same protocol that powers the web, HLS lets you deploy content using ordinary web servers and content delivery networks.


1 Answers

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)

like image 182
Victor Ronin Avatar answered Dec 11 '22 15:12

Victor Ronin