MediaPlayer.onPrepared() is not called
<p>I use media player in service and activity with a button(play/stop stream).<br>
I'm trying to do such a one thing:<br>
start serice only once when activity starts, and than use UI part to operate with media player in service (start, stop streaming). I'm using for it Service Binder.<br>
But when i click on button to start media player, it causes errors:</p>

<pre><code>E/MediaPlayer: start called in state 1
E/MediaPlayer: error (-38, 0)
</code></pre>

<p>Than i added the flag <code>isPrepared</code> to <code>onPrepared()</code> and on play stream button click check the flag. Flag is always false.
It seems that <code>onPrepare()</code> is not called or smth like that. Why? What's wrong?</p>

<p><strong>UPDATED</strong><br>
<strong>Activity:</strong></p>

<pre><code>public class MainActivity extends AppCompatActivity {

String url = "http://62.80.190.246:8000/ProstoRadiO128";
Button mPlayPauseButton;
boolean musicPlaying = false;
Intent serviceIntent;
MyService mService;
boolean mBound = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initViews();
    initListeners();
}

@Override
protected void onStart() {
    super.onStart();
    serviceIntent = new Intent(this, MyService.class);
    serviceIntent.putExtra("url", url);
    bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
    startService(serviceIntent);
    musicPlaying = true;
    mPlayPauseButton.setBackgroundResource(R.drawable.pause);
    Log.d("", "mConnection: " + mConnection);
}

@Override
protected void onStop() {
    super.onStop();
    if (mBound) {
        unbindService(mConnection);
        mBound = false;
    }
}

private ServiceConnection mConnection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        MyService.MyServiceBinder binder = (MyService.MyServiceBinder) service;
        mService = binder.getService();
        mBound = true;
        Log.d("", "in onServiceConnected: mBound = " + mBound);
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mBound = false;
    }
};


private void initViews() {
    mPlayPauseButton = (Button) findViewById(R.id.btn_play_pause);
    mPlayPauseButton.setBackgroundResource(R.drawable.play);
}

private void initListeners() {
    mPlayPauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playPauseClick();
        }
    });
}

private void playPauseClick() {
    if (musicPlaying == false) { //mBound &amp;&amp;
        Log.d("", "mBound: " + mBound);
        mService.startStream();
        mPlayPauseButton.setBackgroundResource(R.drawable.pause);
        musicPlaying = true;
    }
    else if (musicPlaying == true) { //!mBound
        mService.stopStream();
        mPlayPauseButton.setBackgroundResource(R.drawable.play);
        musicPlaying = false;
    }
}
}
</code></pre>

<p><strong>UPDATED</strong>
<strong>Service:</strong></p>

<pre><code>public class MyService extends Service implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener{

String TAG = "PlayerService__Log";
String url;
MediaPlayer mediaPlayer;
private final IBinder mBinder = new MyServiceBinder();
boolean isPrepared;

public class MyServiceBinder extends Binder {
    MyService getService() {
        return MyService.this;
    }
}

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

@Override
public void onCreate() {
    Log.v(TAG, "Creating Service");
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setOnCompletionListener(this);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Log.d(TAG, "onStartCommand");

    url = intent.getStringExtra("url");
    Log.d(TAG, "url: " + url);
    if (!mediaPlayer.isPlaying()) {
        try {
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(url);
            mediaPlayer.prepareAsync();
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, e.getClass().getName() + " " + e.getMessage());
        }
    }
    return START_STICKY;
}

@Override
public void onPrepared(MediaPlayer mp) {
    mp.start();
    Log.d(TAG, "media player prepared");
    isPrepared = true;
}

@Override
public void onCompletion(MediaPlayer mp) {
    Log.d(TAG, "onCompletion");
}

@Override
public void onDestroy() {
    super.onDestroy();
    if (mediaPlayer != null) {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
        }
        mediaPlayer.release();
        mediaPlayer = null;
    }
}

public void startStream() {
    if (!mediaPlayer.isPlaying() ) { //&amp;&amp; isPrepared == true
        mediaPlayer.start();
        Log.d(TAG, "media player started");
    }
    else {
        Log.d(TAG, "media player is not prepared");
        //isPrepared = false;
    }
}

public void stopStream() {
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.stop();
        Log.d(TAG, "media player stoped");
    }
}
}
</code></pre>