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

Merging media sources #2052

Closed marcin-adamczewski closed 7 years ago

marcin-adamczewski commented 7 years ago

ExoPlayer version: 2.0.4

Hi,

Is it possible to merge two audio media sources? MergingMediaSource class seems to not handle that because only first audio media source is played.

To be more specific about my case I want to play some "sound effects" (which are separate .mp3 files) in specific time of some song (which is another .mp3 file or some url). One idea to handle this may be to track ExoPlayer playback and play sound effects using another ExoPlayer instance at specific playback time of first ExoPlayer instance.

Is it possible to handle this case out of the box using ExoPlayer? If not, it would be nice to have such a feature that allows to merge a number of media sources with possibility to delay some of them, e.g. new MergingMediaSource(songMediaSource(), soundEffectMediaSource().delay(10s), soundEffectMediaSource().delay(20s)); This would allow to compose number of media sources in time as we want. Delaying media sources feature would also be helpful in ConcatenatingMediaSource so we can customise break time between songs in playlist.

Summarising requested features:

This issue is partially related to #1828

I look forward to your reply.

ojw28 commented 7 years ago

Merging two sources that expose audio tracks is possible in the sense that the merged source will expose all of the audio tracks provided by its children. However it is not possible to then have more than one of the audio tracks enabled at a time, which is what you're wanting to do. I'm not sure whether Android even provides a way to accurately synchronize two AudioTrack instances together. If not, you'd likely have to do something yourself to merge the audio track data before feeding it into a single AudioTrack.

I don't think this is something we have any plans to support.

benjosantony commented 7 years ago

@ojw28 As I understand from your comment it is not possible to have two audio tracks enabled at a time. But would it be possible to do this for a mix of audio and video source.

Something like this

MergingMediaSource(songMediaSource(), videoMediaSource().delay(10s));

The idea is to be able to play audio track and to be able to playback video after a delay.

ojw28 commented 7 years ago

It's possible merge audio and video sources, yes. We don't provide any functionality for adding a delay to one of the sources, however. It might be possible for you to implement it yourself with a custom MediaSource, but we don't have the cycles to be able to provide guidance about how you might go about doing this; sorry.