最奇怪的事情。播放动画时,我可以清楚地听到我的音效,但是当我没有播放动画时,音效会中断。这是代码:
private void Feedback(boolean success)
{
Log.d(TAG, "Feedback");
if(success)
{
PlayCreatureSound();
ShowAnimatedCreature();
}
else
{
PlayFailedSound();
}
}
private void PlayCreatureSound()
{
Log.d(TAG, "PlayCreatureSound");
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float leftVolume = curVolume/maxVolume;
float rightVolume = curVolume/maxVolume;
spCreatureVoice.play(iCreatureVoicesId[lastCreature.ordinal()], leftVolume, rightVolume, 1, 0, 1);
}
private void PlayFailedSound()
{
Log.d(TAG, "PlayFailedSound");
spCreatureVoice.stop(iCreatureVoicesId[FeedbackCreature.FC_COUNT.ordinal()]);
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float leftVolume = curVolume/maxVolume;
float rightVolume = curVolume/maxVolume;
spCreatureVoice.play(iCreatureVoicesId[FeedbackCreature.FC_COUNT.ordinal()], leftVolume, rightVolume, 1, 0, 1);
}
private void ShowAnimatedCreature()
{
Log.d(TAG, "ShowAnimatedCreature");
// show the creature
ibtnShapes[lastTargetLocation].setImageBitmap(bmCreatures[lastCreature.ordinal()]);
// animate
ibtnShapes[lastTargetLocation].startAnimation(rotate[0]);
}
我已经尝试过: 1. 切换文件 2. 使用 MediaPlayer 3. 删除“spCreatureVoice.stop(...” 4. 更改优先级