如何在Android上玩m3u8?

时间:2011-06-01 09:27:35

标签: android media-player aac

据我了解,Android 3.0及以上版本可以播放无线电流媒体m3u8 - http://developer.android.com/guide/appendix/media-formats.html

我将此链接 - http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8放入MediaPlayer,但在LogCat中我得到:

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.

这是我的源代码:

    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();
            } 
        }
    });
}

5 个答案:

答案 0 :(得分:4)

点击此链接后: 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!)

最后给出了答案:

基本上在Android v2.3& v3.0,使用非标准的httplive://方案, 在3.1中使用http://但是在一些代码中解决了如何在媒体框架中调用相关方法的问题。

答案 1 :(得分:4)

这是我在Android中播放.M3U8流媒体的示例

<强> 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)); 
                }
            });
    }
}

我见过很多人在播放.M3U8时遇到问题,这取决于用于流媒体的编解码器以及与设备的兼容性,例如我的.m3u8文件只支持屏幕为1200 x800及更高。

答案 2 :(得分:3)

也许你可以试试Vitamio插件,http://vov.io/vitamio/

Vitamio是适用于所有Android设备的多媒体框架。 Vitamio的工作方式类似于Android的默认MediaPlayer,除了它包含更强大的功能。它完全免费! 网络协议

音频和视频播放支持以下网络协议:

MMS
RTSP (RTP, SDP)
HTTP progressive streaming
HTTP live streaming (M3U8), for Android 2.1+

答案 3 :(得分:3)

尝试ExoMedia,流媒体就像以下一样简单:

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

我与m3u8合作得很好。

答案 4 :(得分:0)

您可以使用FFmpegMediaPlayer:

https://github.com/wseemann/FFmpegMediaPlayer