Skip to content

Instantly share code, notes, and snippets.

@paramsen
Created August 28, 2020 11:49
Show Gist options
  • Save paramsen/813e03792a6d4e8f22471bff41959cc8 to your computer and use it in GitHub Desktop.
Save paramsen/813e03792a6d4e8f22471bff41959cc8 to your computer and use it in GitHub Desktop.
ExoPlayer play file from assets (in this case audio, repeat for eternity)
val assetFactory = DataSource.Factory { AssetDataSource(context) }
val source = ProgressiveMediaSource.Factory(assetFactory).createMediaSource(Uri.parse("assets:///alarm_sound_1.mp3"))
val exo = SimpleExoPlayer.Builder(context).build().apply {
repeatMode = Player.REPEAT_MODE_ALL
volume = 1f
audioAttributes = AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build()
prepare(source)
playWhenReady = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment