将旧版ExoPlayerAPI代码迁移到2.16.1版时出现的问题
我有以下使用ExoPlayer2.4.0
简单播放视频的API的代码。我试图将其迁移到最新的API版本(2.16.1
),但许多API和我使用的代码不再在那里工作。例如,newSimpleInstance()
不再被识别等。
如何将代码更新到最新的API?
以下是我到目前为止使用ExoPlayer2.4.0
的代码:
Uri uri = Uri.parse("https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd");
// bandwidthmeter is used for getting default bandwidth
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
// track selector is used to navigate between video using a default seekbar.
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
// we are adding our track selector to exoplayer.
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
// we are creating a variable for datasource factory and setting its user agent as 'exoplayer_view'
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
DashMediaSource dashMediaSource = new DashMediaSource(uri, dataSourceFactory,
new DefaultDashChunkSource.Factory(dataSourceFactory), null, null);
// inside our exoplayer view we are setting our player
exoPlayerView.setPlayer(exoPlayer);
// we are preparing our exoplayer with media source.
exoPlayer.prepare(dashMediaSource);
Log.i("BW", "BW: " + bandwidthMeter.getBitrateEstimate());
// we are setting our exoplayer when it is ready.
exoPlayer.setPlayWhenReady(true);
解决方案
参考exoplayer release notes接口中的更改,查找从v2.4.0
到最新版本删除的符号。请记住,v2.x.0
版本是主要的发行版,并且大多数在API中引入了突破性的变化,因为ExoPlayer没有使用语义版本控制。
例如here您可以发现ExoPlayerFactory
已被删除,您应该改用SimpleExoPlayer.Builder
。
相关文章