Created
March 9, 2018 01:02
-
-
Save nazmulidris/82cebffca8fbd159382fb2c0d89caf69 to your computer and use it in GitHub Desktop.
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 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