外星播放器不显示资产视频



嘿伙计们,我从 2 天开始就一直在尝试在 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'

DefaultDataSourceFactory支持为资产 URI 创建数据源。要播放 MP4 资产,请为播放器准备一个 ExtractorMediaSource ,您可以像这样创建:

new ExtractorMediaSource(
    Uri.parse("asset://splash_video.mp4"),
    new DefaultDataSourceFactory(context, userAgent),
    new DefaultExtractorsFactory(),
    null,
    null);

相关内容

  • 没有找到相关文章

最新更新