Grapes
Grapes

Reputation: 2563

Android MediaPlayer automatically plays the next song

I have very basic media player code:

AssetFileDescriptor FileDescriptor = getAssets().openFd(musicPth);

MusicPlayer.setDataSource(FileDescriptor.getFileDescriptor());
MusicPlayer.prepare();
MusicPlayer.start();

For some reason when the song finishes, the player automatically plays the next song in the folder!

I've tried setOnCompletionListener and setLooping functions but it seems they don't effect the player and it just goes to the next song.

If I exclude the second mp3 then the player loops the same song which is what I want.

Very strange behavior, am I missing something?

Upvotes: 0

Views: 2046

Answers (1)

Grapes
Grapes

Reputation: 2563

I have seemed to fix my problem by changing the setDataSource() function to this:

AssetFileDescriptor FileDescriptor = getAssets().openFd(musicPth);

MusicPlayer.setDataSource(FileDescriptor.getFileDescriptor(), 
    FileDescriptor.getStartOffset(), 
    FileDescriptor.getLength());

FileDescriptor.close();

Upvotes: 2

Related Questions