简体   繁体   中英

ExoPlayer 2.11.1 DefaultBandwidthMeter(); deprecated

I am playing video on Android using ExoPlayer. But " DefaultBandwidthMeter();" is deprecated.

    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);

What should I use insead of this and according to that with what I should replace the following line which is using theis bandwidthMeter?

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

You should use DefaultBandwidthMeter.Builder . Source from ExoPlayer documentation .

If you use HLS Media Type you should this:

val defaultHttpDataSourceFactory = DefaultHttpDataSource.Factory()

Note: It worked this version: implementation 'com.google.android.exoplayer:exoplayer:2.16.1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM