Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 255
John D Avatar asked Jun 23 '14 18:06

John D


2 Answers

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.

like image 118
Brian Cooley Avatar answered Sep 28 '22 17:09

Brian Cooley


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

like image 40
Josh Avatar answered Sep 28 '22 16:09

Josh