HTML5 <audio> playback with fade in and fade out

后端 未结 5 1020
渐次进展
渐次进展 2020-12-01 00:03

I\'d like to start and stop HTML5 playback in a random position with fade in and fade out periods to smooth the listening experience.

What kind of mechanisms exists

5条回答
  •  我在风中等你
    2020-12-01 01:03

    This is a simple timeout function for fading the audio (from 0 to 100 in this case). It uses a global variable. Still struggling with a whole package though. I'll definitely be checking out sfjedi's jQuery way.

    function FadeIn() {
    
        var sound = document.getElementById('audiosnippet');
    
        var vol = $.global.volume;
    
        if ( vol < 100 )
            {
                sound.volume = (vol / 100);
                $.global.volume = $.global.volume + 10;
                setInterval(function() { FadeIn() }, 1200);
            }
    
        }
    }
    

提交回复
热议问题