Skip to content

Playlist API

Devrath edited this page Oct 31, 2021 · 3 revisions

Concatenating a Media Item to prepare the list

  • Using ConcatenatingMediaSource, it is possible to play the sequence of MediaItem where we can prepare each media item and chain one after another.
  • Earlier this support was not available but now the player has a built-in feature available for this in the latest version of exo-player.
  • We prepare the media source and send it to the exo-player, and the exo-player internally takes care of making the media source for each item in the list, and we explicitly do not need to worry about it.
  • MediaItem is added to the playlist, the player converts it internally into a playable MediaSource. By default, the library does this using a DefaultMediaSourceFactory.

Code snippet showing preparing media item list

SimpleExoPlayer.Builder(context)
            .setTrackSelector(trackSelector)
            .build()
            .also { exoPlayer ->
                callback.invoke(PlaylistExoplayerAction.BindCustomExoplayer(exoPlayer))
                val videosList = dashItemList()
                val type: String = MimeTypes.APPLICATION_MPD // -> DASH
                val mediaItems: MutableList<MediaItem> = ArrayList()
                for (i in 0 until videosList.size) {
                    val mediaItem = MediaItem.Builder()
                        .setUri(videosList[i].uri)
                        .setMimeType(type)
                        .build()
                    mediaItems.add(mediaItem)
                }
                exoPlayer.setMediaItems(mediaItems)
                exoPlayer.playWhenReady = playWhenReady
                exoPlayer.seekTo(currentWindow, playbackPosition)
                exoPlayer.prepare()
            }