ExoPlayer: How to play http live stream?

左心房为你撑大大i 提交于 2019-12-07 09:32:14

问题


i want to use ExoPlayer library for my Android application to play live streaming videos.

I was looking through the exoplayer website and documentation as well as Github page but i wasn't satisfied with the explanations.

Anyone can give me a hint how do you play a http live streaming video through ExoPlayer?

Thanks in advance.


回答1:


I was able to play LiveStream right away in ExoPlayer.

Just download this sample at https://drive.google.com/file/d/0Byr1H33Pe7u-MW93UUpmMUhGTTQ/view and modify Uri

video_url = "http://cspan1-lh.akamaihd.net/i/cspan1_1@304727/index_1000_av-p.m3u8";

Note: some m3u8 files wont play because of incorrect format
Check Supported formats here https://google.github.io/ExoPlayer/supported-formats.html




回答2:


you can use exomedia exomedia library which uses exoplayer. This library is very simple to use. just add below dependencies in your gradle file

repositories {
    jcenter();
}

dependencies {
    compile 'com.devbrackets.android:exomedia:3.0.5'
}

and in your layout file

<com.devbrackets.android.exomedia.ui.widget.EMVideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    EMVideoView:useDefaultControls="true"/>

Now you can use EMVideoView in your main activity as

public class MainActivity extends AppCompatActivity implements OnPreparedListener{
    EMVideoView emPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        playVideo();
    }


    private void playVideo() {
        emPlayer = (EMVideoView)findViewById(R.id.video_view);
        emPlayer.setOnPreparedListener(this);

        emPlayer.setVideoURI(Uri.parse("your http url"));
    }

    @Override
    public void onPrepared() {
        emPlayer.start();
        Log.v("TAG","video is playing");
    }
}



回答3:


To play the HLS file or live stream (m3u8), you can use a google exoplayer. You just have to specify the type of stream that you are going to play like HLS or DASH to exoplayer.

Intent mpdIntent = new Intent(MainActivity.this, PlayerActivity.class)
                    .setData(Uri.parse("http://devimages.apple.com/samplecode/adDemo/ad.m3u8"))
                    .putExtra(LiveTVPlayerActivity.CONTENT_ID_EXTRA, "My Channel Name")
                    .putExtra(LiveTVPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_HLS)
                    .putExtra(LiveTVPlayerActivity.PROVIDER_EXTRA, "");
            startActivity(mpdIntent);

I hope you will use latest code from github and specify the type of stream that is to be played.



来源:https://stackoverflow.com/questions/38040353/exoplayer-how-to-play-http-live-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!