本文介绍了com.google.android.exoplayer2.source.UnrecognizedInputFormatException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用.cd格式的exoplayer
复制现场表演.
I need to reproduce a live show with exoplayer
in format .mpd.
但我收到此错误:
我不知道为什么!
这是我的代码:
public class MainActivity extends AppCompatActivity {
SimpleExoPlayer exoPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SimpleExoPlayerView exoPlayerView;
exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player_view);
exoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
try {
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
Uri videoURI = Uri.parse("blablabla/manifest.mpd");
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videoURI, dataSourceFactory, extractorsFactory, null, null);
exoPlayerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}catch (Exception e){
Log.e("MainAcvtivity"," exoplayer error "+ e.toString());
}
}
@Override
protected void onDestroy() {
super.onDestroy();
exoPlayer.stop();
}
@Override
protected void onPause() {
super.onPause();
exoPlayer.stop();
}
}
推荐答案
.mpd通常指向DASH清单,这是一种自适应格式.清单列出了播放器可以适应给定带宽条件的不同质量的媒体表示.
.mpd is commonly pointing to a DASH manifest which is an adaptive format. The manifest lists media representations of different qualities with which the player can adapt to given bandwidth conditions.
要播放DASH清单(.mpd),请创建DASH特定的媒体源.
To play a DASH manifest (.mpd) you create a DASH specific media source.
使用DashMediaSource
代替ExtractorsMediaSource
:
// meter bandwidth with media files (video/audio)
DefaultHttpDataSourceFactory mediaDataSourceFactory = new DefaultHttpDataSourceFactory(
Util.getUserAgent(this, "stackoverflow"), BANDWIDTH_METER);
// do not meter bandwidth for manifest loading
DefaultHttpDataSourceFactory manifestDataSourceFactory = new DefaultHttpDataSourceFactory(
Util.getUserAgent(this, "stackoverflow"));
// create the media source for DASH
MediaSource mediaSource = new DashMediaSource.Factory(
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
manifestDataSourceFactory)
.createMediaSource(uri, null, null);
// prepare the player
player.setPlayWhenReady(true);
player.prepare(mediaSource);
这篇关于com.google.android.exoplayer2.source.UnrecognizedInputFormatException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!