Created
October 24, 2011 13:43
-
-
Save sakurabird/1309058 to your computer and use it in GitHub Desktop.
Untouchable アラーム音量
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//インスタンス変数を宣言 | |
AudioManager am; | |
SeekBar ringVolSeekBar; | |
TextView ringVolText; | |
// アラーム音量 | |
am = ( AudioManager ) getSystemService( Context.AUDIO_SERVICE ); | |
//現在の音量を取得します | |
int ringVolume = am.getStreamVolume( AudioManager.STREAM_MUSIC ); // 音量の取得 | |
ringVolSeekBar = ( SeekBar ) findViewById( R.id.ringVolSeekBar ); // 音量シークバー | |
//画面のシークバーの最大値をシステムから取得した最大値にセットします | |
ringVolSeekBar.setMax( am.getStreamMaxVolume( AudioManager.STREAM_MUSIC ) ); // 最大音量の設定 | |
ringVolText = ( TextView ) findViewById( R.id.ringVolText ); // 音量TextView | |
ringVolText.setText( "Volume:" + ringVolume ); // TextViewに設定値を表示 | |
//現在の音量をAudioManagerにセットします | |
am.setStreamVolume( AudioManager.STREAM_MUSIC, ringVolume, 0 ); // 音量設定 | |
ringVolSeekBar.setProgress( ringVolume ); // 音量をSeekBarにセット | |
//画面のシークバーが変更された時は音変更された音量をAudioManagerにセットします | |
ringVolSeekBar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { | |
publicvoid onProgressChanged( SeekBar seekBar, int progress, boolean fromUser ) { | |
ringVolText.setText( "Volume:" + progress ); // TextViewに設定値を表示 | |
am.setStreamVolume( AudioManager.STREAM_MUSIC, progress, 0 ); // 音量設定 | |
ringVolSeekBar.setProgress( progress ); // 音量をSeekBarにセット | |
} | |
publicvoid onStartTrackingTouch( SeekBar seekBar ) { | |
} | |
publicvoid onStopTrackingTouch( SeekBar seekBar ) { | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment