Home » Android » Android – Exoplayer 2 – play multiple sounds/audio simultaneously – MergingMediaSource

Android – Exoplayer 2 – play multiple sounds/audio simultaneously – MergingMediaSource

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m using in my app several instances of SimpleExoPlayer to play audio file (Wav file). I want play all these files simultaneously. Now there is some small gap between these files. Is it possible to have only one instance of SimpleExoPlayer with more sounds files?

I tried use MergingMediaSource but it’s now working. It’s playing only one Wav file (not all).

Code:

        MediaSource ms = new MergingMediaSource(audioSources.toArray(new MediaSource[audioSources.size()]));
        mMediaPlayerTracker1.addListener(myExoPlayerEventListener);
        mMediaPlayerTracker1.prepare(ms);

        //Adding MediaSource to the ArrayList
        audioSources.add(new ExtractorMediaSource(
                    Uri.fromFile(new File(path)), mediaDataSourceFactory, defaultExtractorsFactory,
                    mainHandler, exoEventListener));
How to&Answers: