这是我的Exoplayer代码:
我在Fragment类中使用此代码。我正在从网络流式传输视频,获取视频网址并将uri传递给initializePlayer(uri)方法。
private void initializePlayer(Uri mediaUri) {
if (mExoPlayer == null) {
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(),
trackSelector);
mSimpleExoPlayerView.setPlayer(mExoPlayer);
DefaultHttpDataSourceFactory dataSourceFactory = new
DefaultHttpDataSourceFactory("Baking");
ExtractorsFactory extractorsFactory = new
DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(mediaUri,
dataSourceFactory, extractorsFactory,
null, null);
mExoPlayer.prepare(mediaSource);
}
}