0

Hey guys I've been trying to show video in exoPlayer since 2 days but getting no progress, Please guide what I've been doing wrong. Thank in advance.

This is my code call from on create function.

 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();
    }
}

My library version is

compile 'com.google.android.exoplayer:exoplayer:r2.5.4'
Ahsan Saeed
  • 560
  • 7
  • 18

1 Answers1

0

DefaultDataSourceFactory supports creating data sources for asset URIs. To play an MP4 asset, prepare the player with an ExtractorMediaSource, which you can create like this:

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