0
我正在研究一個讓用戶設置鬧鐘的應用程序。我正在使用媒體播放器播放警報聲。我想將媒體音量設置爲70%。這是我如何做的。媒體音量設置爲最大,我希望它在70%
@Override
protected void onResume(){
super.onResume();
mDbHelper.open();
AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
originalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); // we get the current volume from the system
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 70, 0);
mediaPlayer = MediaPlayer.create(getBaseContext(),R.raw.midi_sound);
mediaPlayer.setScreenOnWhilePlaying(true);
mediaPlayer.setLooping(true);// we set the sound to loop.
if(!mediaPlayer.isPlaying()){// if the media player is not playing , make it start
mediaPlayer.start();
}
}
但是卷被設置爲最大。我的用戶可能會在使用該應用程序時聽到他們的耳機,我不想用最大音量來防禦他們。我如何將音量設置爲70%而不是最大音量?
注意:我將在onPause方法中將音量設回原始音量。