Search code examples
androidandroid-mediaplayer

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!


Solution

  • 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.