Skip to content

Instantly share code, notes, and snippets.

@VDenis
Created August 7, 2021 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VDenis/3e99589d074fa99fba10c775796e595c to your computer and use it in GitHub Desktop.
Save VDenis/3e99589d074fa99fba10c775796e595c to your computer and use it in GitHub Desktop.
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