google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.72k stars 6.03k forks source link

Allow setting audio volume on a per-MediaSource basis #9012

Open alexgomes09 opened 3 years ago

alexgomes09 commented 3 years ago

I am working on a project which requires me to mix multiple media sources. While MergingMediaSource is capable to do the merging but I would also need a way to control volume for each media source.

audiosource1 + audiosource2 = mergemediasource1 (volume 1.0) audiosource3 + audiosource4 + audiosource5 = mergemediasource2 (volume 0.5)

mergemediasource1 + mergemediasource2 = concatenatingMediaSource --> provide this to exoplayer

Is it possible somehow?

andrewlewis commented 3 years ago

This is not supported currently I'm afraid.

You can probably implement this behavior on the app side by listening for position discontinuities (or changes in the current window index/media item) and setting the player volume accordingly based on the window index, but this approach doesn't let you set the volume at the precise moment the new item's content starts playing.

To get it to work "perfectly" with seamless transitions I think you'd need to do a more complicated customization that modifies the audio sample volume before they're written to the audio track (perhaps the discussion in #6090 could be a starting point).

I'll mark this as a enhancement for now given it's come up a couple of times but I think it's unlikely we will get round to it soon.