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.75k stars 6.03k forks source link

How to play multiple Clipped media sources of Audios with different start timestamps using Merged Media Source? #9685

Open tamanna-seg opened 3 years ago

tamanna-seg commented 3 years ago

Unfortunately we can't answer all questions. Unclear questions or questions with insufficient information may not get attention.

Before filing a question:

When filing a question:

Describe your question in detail.

In case your question refers to a problem you are seeing in your app:

In case your question is related to a piece of media:

Don't forget to check supported formats and devices (https://exoplayer.dev/supported-formats.html).

If there's something you don't want to post publicly, please submit the issue, then email the link/bug report to dev.exoplayer@gmail.com using a subject in the format "Issue #1234", where #1234 is your issue number (we don't reply to emails).

tamanna-seg commented 3 years ago

@christosts @marcbaechinger is this can be possible or not with Exo player?

marcbaechinger commented 3 years ago

You should be able to instantiate a media source to an audio file and then use a number of ClippingMeidaSources to wrap them. Then use a MerginMediaSource to merge the clipping media sources together and call for instance exoPlayer.setMediaSource(mergingMediaSource).

You would then need to select the track that you want to play with the TrackSelector. If you are using the EventLogger it should be easy to see the tracks in the log.

If that isn't what you were asking, then can you please clarify your question a bit?

tamanna-seg commented 3 years ago

With Clipped media source, media source played between start and end time and when I merged multiple clipped source to Merged Media source all source are played from 0 position but I want to play sources to start also from different timestamps.

Code snippet is:

ClippingMediaSource videoSource0 = new ClippingMediaSource(mediaSource1, 0,  2000000,true,true,false);
ClippingMediaSource videoSource1 = new ClippingMediaSource(mediaSource2, 2000000,  5000000,true,true,false);
ClippingMediaSource videoSource2 = new ClippingMediaSource(mediaSource3,  7000000, 10000000,true,true,false);
ClippingMediaSource videoSource3 = new ClippingMediaSource(mediaSource4,  1200000, 13000000,true,true,false);

mergingMediaSource = new MergingMediaSource(true,false,videoSource0, videoSource1,videoSource2,videoSource3);
player.prepare(mergingMediaSource,true,false);

In this clipped sources are clipped but all 4 sources played together i.e. from 0 position.

marcbaechinger commented 3 years ago

I'm not sure I understand what you mean with I want to play sources to start also from different timestamps. I thought that is why you wrap the source with a ClippingMediaSource. Once they are merged in a MergingMediaSource the source is played from position 0 of the merging media source. Position 0 of the merging media source is then mapped to position 0 of the clipped media sources that are clipped to the corresponding position according to the clipping properties.

So in you example, position 0 of the merging source is 0, 2000000, 7000000, 1200000 of the merged sources respectively.

Please note that by default a player has only a single audio renderer. Which means you can only play one audio source at the same time. The player does not mix these sources together or the like. You need to select one of the audio sources to be rendered by the single audio renderer instance. If you want to play more than a single audio stream at once you need to setup the player accordingly with multiple audio renderes which is non-trivial. If you want to look into this, you may want to check issues #6589 or #4261 which explains this in more detail.