我有两个设备可以测试我的游戏:一个美国电信手机(SCH-R880)和一个Kindle Fire,后者比手机性能更强。
我有几个短音效(少于或约1秒)。为了节省内存,我加载、播放和释放其中一些音效。在手机上它们(大多数情况下)正常播放。然而,在Kindle Fire上,它们被切断了。非常短的声音被迅速切断,我什么都听不到。那些已经被加载并保留的声音则正常播放。
有人知道这是怎么回事吗?我是否把我的媒体释放得太快了?以下是其中一个实例。在手机上我听到“Level two!”,但在Kindle上我听到类似“Lev tw”的声音。
mpNum = null;
try
{
switch (level)
{
case 2:
mpNum = MediaPlayer.create(contxt, R.raw.l2); break;
case 3:
mpNum = MediaPlayer.create(contxt, R.raw.l3); break;
case 4:
mpNum = MediaPlayer.create(contxt, R.raw.l4); break;
case 5:
mpNum = MediaPlayer.create(contxt, R.raw.l5); break;
case 6:
mpNum = MediaPlayer.create(contxt, R.raw.l6); break;
case 7:
mpNum = MediaPlayer.create(contxt, R.raw.l7); break;
case 8:
mpNum = MediaPlayer.create(contxt, R.raw.l8); break;
default:
return;
}
MediaPlayer vLevel = MediaPlayer.create(contxt, R.raw.level);
vLevel.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
});
vLevel.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer mpl)
{
mpNum.start();
mpl.release();
}
});
mpNum.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer mp)
{
mp.release();
}
});
}
catch (Exception e) {}
为了试图解决这个问题,我尝试使用SoundPool,但它没有起作用;我什么也听不到。以下是我尝试使用SoundPool播放音乐的步骤:SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
soundPool.load(contxt, R.raw.song2, 1);
AudioManager mgr = (AudioManager)contxt.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeMax;
soundPool.play(1, volume, volume, 1, 5, 2);
更新
我注意到当应该播放但没有播放的声音时,会出现以下错误:
AudioPolicyManager: stopOutput() oldDevice 2
AudioPolicyManager: [getDeviceForStrategy] strategy : 0,forceUse(0)