Skip to content

Instantly share code, notes, and snippets.

@nazmulidris
Created March 9, 2018 01:02
Show Gist options
  • Select an option

  • Save nazmulidris/82cebffca8fbd159382fb2c0d89caf69 to your computer and use it in GitHub Desktop.

Select an option

Save nazmulidris/82cebffca8fbd159382fb2c0d89caf69 to your computer and use it in GitHub Desktop.
val mediaMap = mapOf<SourceType, Uri>(
local_audio to Uri.parse("asset:///audio/file.mp3"),
local_video to Uri.parse("asset:///video/file.mp4"),
http_audio to Uri.parse("http://site...file.mp3"),
http_video to Uri.parse("http://site...file.mp4")
)
enum class SourceType {
local_audio, local_video, http_audio, http_video, playlist;
}
fun buildMediaSource(sourceType: SourceType): MediaSource {
return when (sourceType) {
playlist -> {
return DynamicConcatenatingMediaSource(
createExtractorMediaSource(local_audio),
createExtractorMediaSource(local_video),
createExtractorMediaSource(http_audio),
createExtractorMediaSource(http_video)
)
}
else -> { return createExtractorMediaSource(sourceType) }
}
}
private fun createExtractorMediaSource(sourceType: SourceType): MediaSource {
return ExtractorMediaSource.Factory(
DefaultDataSourceFactory(mContext, "exoplayer-learning"))
.createMediaSource(mediaMap.get(sourceType))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment