9

As i understood, Android 3.0 and above are able for play radio streaming m3u8 - http://developer.android.com/guide/appendix/media-formats.html

I put this link - http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8 into MediaPlayer but in LogCat i get:

06-01 09:04:44.287: INFO/LiveSession(33): onConnect 'http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8'
06-01 09:04:44.287: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio.m3u8 @0
06-01 09:04:44.747: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio.m3u8 @0
06-01 09:04:45.019: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio/ssnr_052311_071632_78731.aac @0
**06-01 09:04:45.817: ERROR/LiveSession(33): This doesn't look like a transport stream...**
06-01 09:04:45.967: INFO/HTTPLiveSource(33): input data EOS reached.

This is my source code:

    mp = new MediaPlayer();        
    start.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub              
            try {

                mp.setDataSource("http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8");
                mp.prepare();
                mp.start();

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }
    });

    stop.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {

                mp.stop(); 
                mp.reset();

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }
    });
}
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Saasha
  • 277
  • 1
  • 2
  • 8
  • you can see this post: [videoview][1] [1]: http://stackoverflow.com/questions/17697670/android-does-not-display-m3u8-format-in-videoview-only-sound – evan Oct 23 '13 at 08:24

6 Answers6

5

Try ExoMedia, streaming is as easy as:

emVideoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.mp4"));

I works well with m3u8.

Hendra Anggrian
  • 5,780
  • 13
  • 57
  • 97
5

Following this link trail: http://code.google.com/p/android/issues/detail?id=14646

->

http://code.google.com/p/android/issues/detail?id=16884

->

http://code.google.com/p/android/issues/detail?id=17118

(ARGGGGH!)

Gives the answer in the end:

basically in Android v2.3 & v3.0, use the non-standard httplive:// scheme, in 3.1 use http:// but with some code workaround in how you call the relevant methods in the media framework.

Maks
  • 7,562
  • 6
  • 43
  • 65
  • I haven't tried it myself, but the links I referenced suggest that it should work in 2.3 & 3.0 using the "httplive" url scheme and normal "http" for v3.1+ – Maks Jun 17 '12 at 03:42
4

This is my example of how to play .M3U8 Streaming in Android

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/myVideoView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Main.java

package com.grexample.ooyalalive;

import java.net.URL;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class Main extends Activity {

    private String urlStream;
    private VideoView myVideoView;
    private URL url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_vv);//***************
            myVideoView = (VideoView)this.findViewById(R.id.myVideoView);
            MediaController mc = new MediaController(this);
            myVideoView.setMediaController(mc);         
            urlStream = "http://jorgesys.net/i/irina_delivery@117489/master.m3u8";
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    myVideoView.setVideoURI(Uri.parse(urlStream)); 
                }
            });
    }
}

I have seen a lot of people have problems playing .M3U8, it depends on the codecs used for the streaming and compatibility with the device, for example some of my .m3u8 files are only supported in devices with screens of 1200 x800 and higher.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
4

Maybe you can try the Vitamio plugin, http://vov.io/vitamio/

Vitamio is a multimedia framework for all Android devices. Vitamio works like the Android's default MediaPlayer except that it includes much more powerful features. And it's absolutely free ! Network Protocols

The following network protocols are supported for audio and video playback:

MMS
RTSP (RTP, SDP)
HTTP progressive streaming
HTTP live streaming (M3U8), for Android 2.1+
JamesAnd
  • 41
  • 2
  • Just donwload code from Git hub .. but not able compile code as videoView.setPath is not defined (added ZI and Bundle as library project ).. pls help me – Code_Life Jan 02 '13 at 07:25
  • The problem with Vitamio: it's not smooth for some streams. – mxg Feb 09 '13 at 12:02
  • 2
    Also, Vitamio's libraries have a very big footprint on the APK size - they add about 20MB to the APK, and also the libraries are extracted to the app's /data/ on each device, taking up 30MB of device storage. – Elad Nava Sep 09 '13 at 20:54
1

You can use FFmpegMediaPlayer:

https://github.com/wseemann/FFmpegMediaPlayer

david72
  • 7,151
  • 3
  • 37
  • 59
0

I also searched a lot to play m3u8 videos in Exo_player , if we use normal exo player to play m3u8 type videos it would not play for this. We need to do some changes , i did and it working fine for me.

In Kotlin :

 private var exoPlayer: ExoPlayer? = null
    private val playbackStateListener: Player.Listener = playbackStateListener()
    private var currentItem = 0
    private var playbackPosition = 0L
    var url = ""

    //Call this method from onStart() of the Activity.
    private fun initializePlayer() {
        exoPlayer = ExoPlayer.Builder(this).build()
        videoView.player = exoPlayer
        videoView.setKeepContentOnPlayerReset(true)
        var mediaItem =  MediaItem.Builder().
        setUri("YOUR m3u8 url to play video ")
            .setMimeType(MimeTypes.APPLICATION_M3U8).build()

        exoPlayer?.let { exoPlayer ->
            exoPlayer.setMediaItem(mediaItem)
            exoPlayer.playWhenReady = true
            exoPlayer.seekTo(currentItem, 20L)
   
            exoPlayer.prepare()
        }

    }

Now You need to add dependency , do not forget to add dependency in gradle:

 implementation 'com.google.android.exoplayer:exoplayer-hls:2.17.1'

Now for your easyness i will show the xml.

    activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">



    <com.google.android.exoplayer2.ui.StyledPlayerView
        android:id="@+id/videoView"
        app:show_buffering="always"
        app:resize_mode="fit"
        app:keep_content_on_player_reset="false"
        app:use_controller="true"
        android:layout_width="match_parent"
        android:layout_height="480dp" >

    </com.google.android.exoplayer2.ui.StyledPlayerView>


</LinearLayout>