//開始播放聲音 public class PlayVoice { private static MediaPlayer mediaPlayer; public static void playVoice(Context context){ try { mediaPlayer= MediaPlayer.create(context, R.raw.opening); mediaPlayer.start(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mediaPlayer.start(); } }); } catch (Exception e) { e.printStackTrace(); } } //中止播放聲音 public static void stopVoice(){ if(null!=mediaPlayer) { mediaPlayer.stop(); } } }