我的代码工作正常,但突然声音因此错误而停止“MediaPlayer未经发布而最终确定”
我的代码是
public void PLAYSOUND(MediaPlayer Player, boolean value,SOUND sound) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException{
try {
AssetFileDescriptor descriptor = null;
if (Player != null) {
Player.stop();
Player.release();
Player = new MediaPlayer();
}else
Player = new MediaPlayer();
descriptor = GameManager.getInstance().getCurrentActivity().getAssets().openFd("sound/mainmenu.wav");
//AssetFileDescriptor descriptor = GameManager.getInstance().getCurrentActivity().getAssets().openFd("sound/mainmenu.wav");
Player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
Player.setAudioStreamType(AudioManager.STREAM_MUSIC);
descriptor.close();
Player.prepare();
Player.setLooping(value);
if(mCheckVolumeOnOff)
Player.setVolume(2.0f, 2.0f);
else
Player.setVolume(2.0f,2.0f);
Player.start();
} catch (Exception e) {
e.printStackTrace();
}
}
由于.stop()和.release(),我检查过声音没有停止。