'Android Play Audio Sequentially

I have a list of audio file resource Ids resIds and I want to loop through this list and play the audios sequentially one after the other. How could I do that?

I am using android studio and kotlin.

Note: The following code playes all the audio files at once, I want to play them sequentially.

for(id in resIds){
    MediaPlayer.create(activity, id).start()
}



Solution 1:[1]

use setOnCompletionListener - play first audio file and when callback fire then play next one

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 snachmsm