how to get the sound fade in functionality in alarm application using media player in android

前端 未结 2 820
旧巷少年郎
旧巷少年郎 2021-01-26 10:41

Hi i am new to android. I am developing a application with alarm functionality. Here i need to provide the sound fade in functionality. I am using media player to invoke the rin

2条回答
  •  一向
    一向 (楼主)
    2021-01-26 11:09

    I revised @FoamyGuy's answer to avoid compiler and runtime errors and for brevity and clarity:

    // (At this point mp has been created and initialized)
    public float mpVol = 0f;
    mp.setVolume(mpVol, mpVol);
    mp.start();
    
    final Handler h = new Handler();
    h.post(new Runnable() {
        public void run() {
            if (mp.isPlaying()) {
                if (mpVol < 1.0f) {
                    mpVol += .05f;
                    mp.setVolume(mpVol, mpVol);
                    h.postDelayed(this, 500);
                }
            }
        }
    });
    

提交回复
热议问题