android ExoPlayer 2.11.1默认带宽表();不赞成的

qncylg1j  于 2023-01-19  发布在  Android
关注(0)|答案(2)|浏览(181)

我正在Android上使用ExoPlayer播放视频。但是“DefaultBandwidthMeter();“已弃用。

DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

        //DefaultTrackSelector chooses tracks in the media item
        DefaultTrackSelector trackSelector = new DefaultTrackSelector(this);
        trackSelector.setParameters(trackSelector.buildUponParameters().setMaxVideoSizeSd());
        mPlayer = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build();

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayerapp"), bandwidthMeter);
        MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url));

        mPlayer.prepare(mediaSource);

        playerView.setKeepScreenOn(true);
        playerView.requestFocus();
        playerView.setPlayer(mPlayer);
        mPlayer.setPlayWhenReady(true);
        playBackStateListener = new PlayBackStateListener();
        mPlayer.addListener(playBackStateListener);

我应该用什么代替这个,根据这个,我应该用什么来替换下面使用带宽计的行?

DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayerapp"), bandwidthMeter);
0yg35tkg

0yg35tkg1#

您应该使用ExoPlayer文档中的DefaultBandwidthMeter.Builder . Source。

lg40wkob

lg40wkob2#

如果您使用HLS介质类型,您应该:

val defaultHttpDataSourceFactory = DefaultHttpDataSource.Factory()

注意:它工作这个版本:implementation 'com.google.android.exoplayer:exoplayer:2.18.2'

相关问题