Android的闹钟音量逐渐增大 [英] Android Alarm Volume increase gradually

查看:497
本文介绍了Android的闹钟音量逐渐增大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报警类别起着默认的闹钟铃声准时。我想打一个时间内的闹钟铃声播放,音量从最小到最大。我怎样才能提高容积逐渐从最小到最大。是否有样品codeS或项目的任何链接。请大家帮我


解决方案

您可以自己做。没有什么复杂的了。

一旦你的的PendingIntent 被触发,利用处理程序做的越来越多。


  1. 创建类,将采取 AudioManager 上下文应用程序作为参数。<​​/ p >

     公共类VolumeRunnable实现Runnable {私人AudioManager mAudioManager;
    私人处理器mHandlerThatWillIncreaseVolume;
    私人最终静态INT DELAY_UNTILL_NEXT_INCREASE = 30 * 1000,每个增量之间//30秒
    VolumeRunnable(AudioManager audioManager,处理程序处理){
       this.mAudioManager = audioManager;
       this.mHandlerThatWillIncreaseVolume =处理程序;
    }@覆盖
    公共无效的run(){
       INT currentAlarmVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
       如果(currentAlarmVolume!= mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)){//如果我们还没有达到最大   //这里通过添加currentAlarmVolume + someNewFactor增加报警流的体积
            mHandlerThatWillIncreaseVolume.postDelayed(这一点,DELAY_UNTILL_NEXT_INCREASE); //递归再次与体积的每个增量之间有一些延迟调用此可运行,直到上面的条件被满足。
       }}

    }


  2. 调用此的Runnable 一旦的PendingIntent 被触发:



  

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


我希望这给你的想法。请原谅任何错误或拼写错误。

I have an Alarm class which plays the default alarm tone on time. I want to make the alarm tone play, volume from minimum to maximum within a time. How can i increase the volume gradually from minimum to maximum. Is there any links for sample codes or projects. please help me

解决方案

You can do it by yourself. Nothing complicated in it.

Once your PendingIntent is triggered, make use of handlers to do the increasing.

  1. Create class that will take the AudioManager or Context of the app as argument.

      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. Call this Runnable once the PendingIntent is triggered:

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

I hope this gave you idea. Forgive any mistakes or typos.

这篇关于Android的闹钟音量逐渐增大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆