user1437450
user1437450

Reputation: 35

How to play audiofiles one by one

So I have ann array with audiofiles ids. But it depends on user how many ids will be there (he types "a" and R.raw.a appears in array). How can I play this sounds one after another using MediaPlayer. I think I should use OnCompletionListener, but I don't know how many sounds ids will be in array. Should I use

for(){}

Upvotes: 1

Views: 174

Answers (2)

Dinesh
Dinesh

Reputation: 6532

you can set MediaPlayer for OnCompletionListener

public class MyActivity extends Activity
    implements MediaPlayer.OnCompletionListener {

    MediaPlayer player = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        player = new MediaPlayer();
        player.setOnCompletionListener(this);
        ...
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        // Called when playback is complete
        //Play a next song
        ...
    }
}

Welcome!

Upvotes: 1

Raghu Nagaraju
Raghu Nagaraju

Reputation: 3288

Use IntentService to play song. All songs started using intentservice will be in queue. It will play one after other.

Upvotes: 0

Related Questions