0

I'm basically trying to achieve the dub functionality in a video player, using ExoPlayer, however, I can't figure out how to add multiple audio tracks to a video.

I've tried creating multiple MediaSources and adding the the player, but that doesn't work. I also tried to add multiple MediaItems for each language, but the while debugging after the exoplayer envokes the callback that the tracks changes, the tracks size is still 0.

Here's how I do that currently:

resource.url?.let { url ->
    val mediaItem = MediaItem.Builder()
    .setUri(url.toUri()) //this is the video url and works fine, the video plays
    .setSubtitleConfigurations(generateSubtitles()) //subs work fine
    .build()

    val allMediaItems = listOf(mediaItem) + generateDubs()

    with(exoPlayer) {
        setMediaItems(allMediaItems)
        selectAudioTrack()
        prepare()
        play()
    }
}

generateDubs() gets url's of different audios and maps them into MediaItem's instances(which currently is just mock data with 1 audio)

private fun generateDubs(): List<MediaItem> {
    return listOf(MediaItem.fromUri("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"))
}
viewModel.exoPlayer.addListener(object : Listener {
   override fun onTracksChanged(tracks: Tracks) {
      super.onTracksChanged(tracks) // <- debug here shows tracks = 0
      Log.i("mytag", "$tracks")
   }
})

Am I doing something wrong here or am I thinking about this way of achieving dub functionality wrong?

ndriqa
  • 362
  • 2
  • 13

0 Answers0