Exoplayer在切换Stream后卡住了

时间:2018-05-31 15:14:19

标签: android exoplayer

我使用以下代码播放m3u8文件:

    SimpleExoPlayerView = new SimpleExoPlayerView(this);
    simpleExoPlayerView = findViewById(R.id.player_view);

    simpleExoPlayerView.setUseController(false);
    simpleExoPlayerView.requestFocus();
    simpleExoPlayerView.setPlayer(player);

    Uri uri = Uri.parse("https://.../playlist.m3u8");

    DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), bandwidthMeterA);


    MediaSource videoSource = new HlsMediaSource(uri, dataSourceFactory, 1, null, null);

    player.setPlayWhenReady(true); //run file/link when ready to play.
    player.setVideoDebugListener(this); //for listening to resolution change and  outputing the resolution

    player.setVolume(1);

    player.prepare(videoSource);
    player.addListener(this);

现在我点击按钮更改视频质量:

    Button btn = findViewById(R.id.btn);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
            MappingTrackSelector.SelectionOverride override;
            TrackSelection.Factory FIXED_FACTORY = new FixedTrackSelection.Factory();
            for(int y = 0; y < mappedTrackInfo.length; y++) {
                TrackGroupArray tracks =  mappedTrackInfo.getTrackGroups(y);
                for(int i = 0; i < tracks.length; i++) {
                    TrackGroup trackGroup = tracks.get(i);
                    for(int x = 0; x < trackGroup.length; x++) {
                        Format format = trackGroup.getFormat(x);
                        int width = format.width;
                        if (width == 1280) {
                            override = new MappingTrackSelector.SelectionOverride(FIXED_FACTORY, i, x);
                            trackSelector.setSelectionOverride(y, tracks, override);
                        }
                    }

                }
            }
        }
    });

将视频卡片更改几秒后,然后有一个硬切割,可以看到更好的流量。

细。但是我怎么能像在netflix上那样更顺利? 这是我的Gradle:

implementation 'com.google.android.exoplayer:exoplayer-hls:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-core:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.7.3'

谢谢, 菲尔

0 个答案:

没有答案