Created
August 7, 2021 21:16
-
-
Save VDenis/3e99589d074fa99fba10c775796e595c to your computer and use it in GitHub Desktop.
Android: play /raw resource with Exoplayer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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