ExoMedia无法播放m3u8网址

时间:2018-11-07 09:31:28

标签: android exoplayer m3u8

我正在将此库https://github.com/brianwernick/ExoMedia/与Android 5.1+配合使用,我知道该库提供了VideoView可以播放m3u8网址。但是,当我尝试它不起作用。这是我从其Rss获取m3u8网址的link网站。我已经尝试了其他一些示例m3u8网址,并且工作正常。所以也许问题出在这个网站的链接上,但我不知道为什么,有什么帮助吗?

private void setupVideoView() {
    videoView = (VideoView)findViewById(R.id.video_view);
    videoView.setOnPreparedListener(this);

    videoView.setVideoURI(Uri.parse("https://hls.mediacdn.vn/vtv/2018/11/7/0711thoi-tiet-12h30-1541575206215339010832-8cab6.mp4/master.m3u8"));
}

@Override
public void onPrepared() {
    videoView.start();
}

1 个答案:

答案 0 :(得分:0)

您需要使用HlsMediaSource

    HlsMediaSource hlsMediaSource = new HlsMediaSource(Uri.parse(hlsVideoUri), dataSourceFactory, mainHandler, new AdaptiveMediaSourceEventListener() {
        @Override
        public void onLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs) {

        }

        @Override
        public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {

        }

        @Override
        public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {

        }

        @Override
        public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded, IOException error, boolean wasCanceled) {

        }

        @Override
        public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs) {

        }

        @Override
        public void onDownstreamFormatChanged(int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaTimeMs) {

        }
    });
    player.prepare(hlsMediaSource);