Created
March 9, 2018 01:14
-
-
Save nazmulidris/865e87bc97f092c4add1e19988c5d3f7 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
| override fun onCreate(savedInstanceState: Bundle?) { | |
| ... | |
| mediaSession = MediaSessionCompat(this, packageName) | |
| connector = MediaSessionConnector(mediaSession) | |
| // If QueueNavigator isn't set, then mediaSessionConnector won’t handle | |
| // MediaSession actions (they won't show up in the minimized PIP activity): | |
| // [ACTION_SKIP_PREVIOUS], [ACTION_SKIP_NEXT], [ACTION_SKIP_TO_QUEUE_ITEM] | |
| connector.setQueueNavigator(object : TimelineQueueNavigator(mMediaSession) { | |
| override fun getMediaDescription(idx: Int): MediaDescriptionCompat { | |
| return MediaCatalog.list.get(idx) | |
| } | |
| }) | |
| } | |
| object MediaCatalog { | |
| val list = mutableListOf<MediaDescriptionCompat>() | |
| init { | |
| list.add( | |
| with(MediaDescriptionCompat.Builder()) { | |
| setDescription("MP4 loaded from assets folder") | |
| setMediaId("1") | |
| setMediaUri(Uri.parse("asset:///video/...video.mp4")) | |
| setTitle("Stock footage") | |
| setSubtitle("Local video") | |
| build() | |
| }) | |
| list.add( | |
| with(MediaDescriptionCompat.Builder()) { | |
| setDescription("MP3 loaded over HTTP") | |
| setMediaId("2") | |
| setMediaUri(Uri.parse("http://storage.../play.mp3")) | |
| setTitle("Spoken track") | |
| setSubtitle("Streaming audio") | |
| build() | |
| }) | |
| list.add(...) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just stumbled across this reading the medium article -> It's kinda redundant to wrap a Java Builder in Kotlin's "with" stdlib function, isn't it?