3

デフォルトのアラーム音を時間通りに再生する Alarm クラスがあります。時間内にアラーム音を最小から最大まで鳴らしたい。音量を最小から最大まで徐々に上げる方法を教えてください。サンプル コードまたはプロジェクトへのリンクはありますか。私を助けてください

4

1 に答える 1

4

あなたは自分でそれを行うことができます。複雑なことは何もありません。

あなたPendingIntentがトリガーされたら、ハンドラーを使用して増加を行います。

  1. アプリのAudioManagerorを引数とするクラスを作成します。Context

      public class VolumeRunnable implements Runnable{
    
    private AudioManager mAudioManager;
    private Handler mHandlerThatWillIncreaseVolume;
    private final static int DELAY_UNTILL_NEXT_INCREASE = 30*1000;//30 seconds between each increment
    VolumeRunnable(AudioManager audioManager, Handler handler){
       this.mAudioManager = audioManager;
       this.mHandlerThatWillIncreaseVolume = handler;
    }
    
    @Override
    public void run(){
       int currentAlarmVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
       if(currentAlarmVolume != mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)){ //if we havent reached the max
    
       //here increase the volume of the alarm stream by adding currentAlarmVolume+someNewFactor
            mHandlerThatWillIncreaseVolume.postDelayed(this,DELAY_UNTILL_NEXT_INCREASE); //"recursively call this runnable again with some delay between each increment of the volume, untill the condition above is satisfied. 
       }
    
    }
    

    }

  2. がトリガーRunnableされたら、これを呼び出します。PendingIntent

someHandler.post(新しい VolumeRunnable(mAudioManager, someHandler));

これがあなたにアイデアを与えたことを願っています。間違いやタイプミスを許してください。

于 2013-07-17T13:06:04.213 に答える