Is there any possibility to control HTML5 audio volume on IOS?

后端 未结 3 1503
滥情空心
滥情空心 2020-12-18 07:10

I use the html5 audio library Buzz to add sounds to a browser game. There is a toggle button to mute and unmute sound, which works good on desktop and Android devices. Unfor

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 07:57

    I worked around this by simply stopping all sounds and setting a variable isMuted to true or false, so I can check this everywhere a sound is played:

    // set the variable
    var isMuted = false;
    
    // toggle audio
    function toggleMute() {
    
        var toggleAudioBtn = $(".toggleAudio");
    
            if (isMuted == false) {
                sounds.stop();
                isMuted = true;
                toggleAudioBtn.css("background-image", "url('images/ui/btn_audio_mute.png')");
            } else {
                isMuted = false;
                toggleAudioBtn.css("background-image", "url('images/ui/btn_audio.png')");
            }
    
    };
    
    // for every sound check if sound is muted
    if(isMuted == false) {
        sound.play();
    }
    

提交回复
热议问题