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

后端 未结 3 1495
滥情空心
滥情空心 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:30

    To add volume change support to iOS and not rewrite your entire app from html5 audio to web audio for that, you can combine these audio solutions via createMediaElementSource.

    Please see more details at Mozilla website https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource

    0 讨论(0)
  • 2020-12-18 07:35

    I always thought dynamic volume control and certainly crossfading, as we all know, is impossible. Apple has dictated that it be so. Except.... apparently the folk at Kodo Games (specifically Nicola Hibbert?) have pulled it off and made the code available to anyone. I just checked it on iOS 8. Fading and crossfading seem to work!

    Check it out (new site that works): Getting Started with Web Audio API

    0 讨论(0)
  • 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();
    }
    
    0 讨论(0)
提交回复
热议问题