嘿伙计们,我一直试图在exoPlayer中显示视频,但是没有取得任何进展,请指导我做错了什么。 提前谢谢。
这是我在创建函数上的代码调用。
private void initializePlayer() {
simpleExoPlayerView = findViewById(R.id.exoPlayerView);
simpleExoPlayerView.requestFocus();
DataSpec dataSpec = new DataSpec(Uri.parse("assets:///splash_video.mp4"));
player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(), new DefaultLoadControl());
simpleExoPlayerView.setPlayer(player);
final AssetDataSource assetDataSource = new AssetDataSource(this);
try {
assetDataSource.open(dataSpec);
DataSource.Factory factory = new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return assetDataSource;
}
};
player.setPlayWhenReady(true);
DefaultExtractorsFactory defaultExtractorsFactory = new DefaultExtractorsFactory();
MediaSource audioSource = new HlsMediaSource(assetDataSource.getUri(), factory, new Handler(), null);
Log.e(TAG, assetDataSource.getUri().getPath());
player.prepare(audioSource);
} catch (AssetDataSource.AssetDataSourceException e) {
e.printStackTrace();
}
}
我的图书馆版本是
compile 'com.google.android.exoplayer:exoplayer:r2.5.4'
答案 0 :(得分:0)
DefaultDataSourceFactory
支持为资产URI创建数据源。要播放MP4资源,请为播放器准备一个ExtractorMediaSource
,您可以这样创建:
new ExtractorMediaSource(
Uri.parse("asset://splash_video.mp4"),
new DefaultDataSourceFactory(context, userAgent),
new DefaultExtractorsFactory(),
null,
null);