Using ExoPlayer 2.6.1 (https://github.com/google/ExoPlayer)
R.raw.presentation is my presentation.mp4 file.
binding.videoPlayer is a SimpleExoPlayerView element in my xml view.
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector()); binding.videoPlayer.setPlayer(player); final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(context); DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.presentation)); try { rawResourceDataSource.open(dataSpec); DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return rawResourceDataSource; } }; MediaSource videoSource = new ExtractorMediaSource.Factory(factory).createMediaSource(rawResourceDataSource.getUri()); player.prepare(videoSource); } catch (RawResourceDataSource.RawResourceDataSourceException e) { e.printStackTrace(); }
Based on other snippets: