我正在尝试加载在特定事件发生时播放的音效。
出于某种原因,我可以听到声音,但它不能播放整个文件,并且会在中间刹车。
我的声音代码:
public class SoundManager {
private Context context;
private int nudgeSound = R.raw.nudge;
public SoundManager(Context context)
{
this.context = context;
}
public void playNudgeSound()
{
final MediaPlayer mediaPlayer = MediaPlayer.create(context, nudgeSound);
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mediaPlayer.reset();
}
});
mediaPlayer.start();
}
}
我的初始化:
SoundManager soundManager = new SoundManager(this);
soundManager.playNudgeSound();