将旧版ExoPlayerAPI代码迁移到2.16.1版时出现的问题

Issues in migrating older ExoPlayer API code to version 2.16.1(将旧版ExoPlayerAPI代码迁移到2.16.1版时出现的问题)

本文介绍了将旧版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版时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将旧版ExoPlayerAPI代码迁移到2.16.1版时出现的问题

基础教程推荐