向Android流式传输实时视频

21

我应该如何将实时视频流传输到 Android(2.1 及更高版本)?我有两个链接:m3u8f4m (据我所知,不支持 f4m)。

从stackoverflow上看到,使用vitamio可以传输 m3u8(但链接无效)。

除了这种方法外,是否还有其他方式可以传输m3u8视频? 也许还有其他格式可供使用?

谢谢。

4个回答

37

因为没有人回答我的问题,我会自己解决。

如果你想在 Android 2.1 及以上版本上执行 HLT(HTTP Live Stream),可以使用 Vitamio 库。

网站地址:(http://www.vitamio.org/)。

这里是代码示例: 主要的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
            android:layout_height="fill_parent"         xmlns:android="http://schemas.android.com/apk/res/android"
            android:paddingLeft="2px" android:paddingRight="2px"
            android:paddingTop="2px" android:paddingBottom="2px"
            android:layout_width="fill_parent" android:orientation="vertical">

            <io.vov.vitamio.widget.VideoView
                 android:layout_height="fill_parent"
                 android:layout_width="fill_parent" android:id="@+id/VideoView">               
            </io.vov.vitamio.widget.VideoView>
</LinearLayout>

这个类:

import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;



public class LiveStrimingTestActivity extends Activity{

    VideoView videoView;

    private void test_2(){
        String httpLiveUrl = "http://aj.lsops.net/live/aljazeer_en_high.sdp/playlist.m3u8";   
        videoView = (VideoView) findViewById(R.id.VideoView);
        videoView.setVideoURI(Uri.parse(httpLiveUrl));
        MediaController mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        videoView.start();
    }


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        test_2();             
    }     
}

1
在API 23级别的项目中添加此库之前,请先查看以下内容。 https://github.com/yixia/VitamioBundle/issues/394#issuecomment-231802573 - Mahmudul

4

我已经在系统版本为2.2、2.3.4和4.0.4的设备上测试了同一流。在我拥有的设备上,使用常规的VideoView播放此流非常顺畅。我不使用MediaController来播放直播流。其余代码很简单。

initializeVideoView();
mVideoView.setVideoURI(Uri.parse("http://aj.lsops.net/live/aljazeer_en_high.sdp/playlist.m3u8"));
mVideoView.setMediaController(null);
mVideoView.start(); 

0

KickFlip 是一个开源且免费的视频流库,非常容易设置。

Kickflip.initWithApiKey(API_KEY, API_SECRET);
Kickflip.startBroadcastActivity(this, mBroadcastListener);

试一下这个。


0

要将Vitamio添加到您的项目中,只需添加此依赖项。 compile 'me.neavo:vitamio:4.2.2' 然后按照@butter告诉您的那样操作。 祝编码愉快,好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接