Skip to content

Commit

Permalink
Android, maAudioPlay: stop any previous streams of this instance befo…
Browse files Browse the repository at this point in the history
…re starting play.
  • Loading branch information
Fredrik Eldh committed Aug 27, 2013
1 parent aa94976 commit dfed6b5
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ int maAudioPlay(int audio, boolean looping)

if(instance.isDynamic())
{

instance.setPaused(false);
}
else
{
Expand All @@ -747,6 +747,7 @@ int maAudioPlay(int audio, boolean looping)
}
else
{
Log.e("maAudioPlay","mSoundPool.resume " + instance.getStreamID());
mSoundPool.resume(instance.getStreamID());
}
return MA_AUDIO_ERR_OK;
Expand Down Expand Up @@ -785,6 +786,7 @@ int maAudioPlay(int audio, boolean looping)
}
else
{
mSoundPool.stop(instance.getStreamID());
int streamID = mSoundPool.play(data.getAudioID(), instance.getVolume(),
instance.getVolume(), 1, instance.getLooping(), 1.0f);

Expand Down Expand Up @@ -871,31 +873,32 @@ int maAudioPause(int audio)

if(instance.isDynamic())
{

instance.setPaused(true);
}
else
{
AudioData data = instance.getAudioData();

//if((false == instance.isPlaying()) || (true == instance.isPaused()))
if(true == instance.isPaused())
if(true == instance.isPaused() || false == instance.isPlaying())
return MA_AUDIO_ERR_OK;

if(MA_AUDIO_DATA_STREAM == data.getFlags())
{
if(null != mMediaPlayer)
if(null != mMediaPlayer) {
mMediaPlayer.pause();
instance.setPaused(true);
}
}
else
{
int streamID = instance.getStreamID();
if(streamID != -1)
if(streamID != -1) {
mSoundPool.pause(streamID);
instance.setPaused(true);
}
}
}

instance.setPaused(true);

return MA_AUDIO_ERR_OK;
}

Expand Down Expand Up @@ -967,6 +970,7 @@ public void onCompletion(MediaPlayer mp)
// oops.. we got an error during playback
mActiveStreamingAudio = 0;
}
audio.setPlaying(false, false);
}

postAudioEvent(EVENT_TYPE_AUDIO_COMPLETED, mActiveStreamingAudio);
Expand Down

0 comments on commit dfed6b5

Please sign in to comment.