簡單的android MediaPlayer 使用
紅定字體為需要自已修改的地方 R.raw.voice_189是要播放的檔案。先在Res中建一個raw的資料匣,把聲音檔放進去,這裡音檔為voice_189 public static MediaPlayer mediaPlayer; if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } mediaPlayer = MediaPlayer.create( this.context .getApplicationContext(), R.raw.voice_189 ); mediaPlayer.setLooping( true ); // Set looping mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); final AudioManager mAudioManager = (AudioManager) this.context.getSystemService(AUDIO_SERVICE); final int originalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); 想要關掉如下 確是是否在播放中 isPlaying, 然後先STOP,再RESET。最後真得不要再RELEASE if (mediaPlayer.isPlaying()){ mediaPlayer.stop(); mediaPlayer.reset(); mediaPlayer.release(); ...