Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android: play /raw resource with Exoplayer
val player = ExoPlayerFactory.newSimpleInstance(context, DefaultTrackSelector())
val rawDataSource = RawResourceDataSource(context)
// open the /raw resource file
rawDataSource.open(DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.brown)))
// create a media source with the raw DataSource
val mediaSource = ExtractorMediaSource.Factory(DataSource.Factory { rawDataSource })
.createMediaSource(rawDataSource.uri)
// play immediately if true
player.playWhenReady = true
// setup the player using the source
player.prepare(mediaSource)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment