2013-07-17 5 views
3

시간에 기본 알람 음을 재생하는 Alarm 클래스가 있습니다. 한 번에 최소 음에서 최대 음으로 음을 재생하고 싶습니다. 어떻게하면 볼륨을 최소에서 최대로 서서히 증가시킬 수 있습니까? 샘플 코드 또는 프로젝트 링크가 있습니까? 제발 도와주세요Android 알람 볼륨이 점차적으로 증가합니다.

답변

4

혼자서 할 수 있습니다. 아무 것도 복잡하지 않습니다.

PendingIntent이 트리거되면 처리기를 사용하여 증가시킵니다.

  1. AudioManager 또는 인수로 응용 프로그램의 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. PendingIntent 번이 Runnable가 트리거 전화 :

someHandler.post (새 VolumeRunnable (mAudioManager, someHandler));

이 아이디어가 도움이 되었기를 바랍니다. 실수 나 오타를 용서하십시오.

+0

놓친 사람 : 처리기 someHandler = 새 처리기(); 이전 : someHandler.post (new VolumeRunnable (mAudioManager, someHandler))); 다른 사용자의 의견입니다. – jclova

관련 문제