Exoplayer无法播放DASH视频android

时间:2018-03-13 14:53:44

标签: android mpeg-dash exoplayer

我试图在Uri演示应用https://github.com/google/ExoPlayer/blob/release-v2/demos/main/src/main/assets/media.exolist.json

获得exoplayer的帮助下播放DASH视频

当我将网络从WIFI更改为移动数据时,视频质量不会改变,而是开始缓冲。

我的代码

private void initializePlayer() {
        if (player == null) {

            player = ExoPlayerFactory.newSimpleInstance(
                    new DefaultRenderersFactory(this),
                    new DefaultTrackSelector(), new DefaultLoadControl());

            exoPlayerView.setPlayer(player);

            player.setPlayWhenReady(playWhenReady);
            player.seekTo(currentWindow, playbackPosition);
        }


        Uri uri = Uri.parse("http://www.youtube.com/api/manifest/dash/id/3aa39fa2cc27967f/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=A2716F75795F5D2AF0E88962FFCD10DB79384F29.84308FF04844498CE6FBCE4731507882B8307798&key=ik0");
        MediaSource mediaSource = buildMediaSource(uri);
        player.prepare(mediaSource, true, false);

        player.addListener(new PlayerEventListener());
        player.setRepeatMode(Player.REPEAT_MODE_ALL);
        //exoPlayerView.setUseController(false);

    }

    private MediaSource buildMediaSource(Uri uri) {
        DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua");
        DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER));
        return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory).createMediaSource(uri);
    }

gradle这个

compile 'com.google.android.exoplayer:exoplayer-core:2.7.0'
    compile 'com.google.android.exoplayer:exoplayer-dash:2.7.0'
    compile 'com.google.android.exoplayer:exoplayer-ui:2.7.0'

我有什么遗漏吗?

1 个答案:

答案 0 :(得分:0)

这是一个愚蠢的错误

而不是new DefaultTrackSelector()

我用过

TrackSelection.Factory adaptiveTrackSelectionFactory =
                    new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);

new DefaultTrackSelector(adaptiveTrackSelectionFactory)