John D
John D

Reputation: 1545

Android Media Player - start called in state 1

player.reset();
player.setDataSource(url);
// mPlayer.setDataSource(mFileName);
player.prepareAsync();
player.setOnPreparedListener(
     new OnPreparedListener() {
         @Override
         public void onPrepared(MediaPlayer mp) {
             player.start();
         }
     }
);

This is my mediaplayer bit code. I'm doing the exact thing I should be doing in order to have the state of the media player correctly yet I'm still having the error start called in state 1 can anyone help? Thanks a lot!

Upvotes: 5

Views: 7895

Answers (2)

Josh
Josh

Reputation: 2468

Change player.start(); to mp.start();

Upvotes: 6

Brian Cooley
Brian Cooley

Reputation: 11662

I think the problem here is that you need to set the listener before you call player.prepareAsync(); because there is always the possibility (especially if the url points to the disk) that the prepareAsync call might return before the listener is set.

Upvotes: 8

Related Questions