本文介紹了將舊版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
。
這篇關于將舊版ExoPlayerAPI代碼遷移到2.16.1版時出現的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,