简体   繁体   中英

Not able to play sound on iphone using JavaScript but able to play on Android

I am trying to play a sound notification on android and iPhone using JavaScript library but I am only able to play the sound on android and not on iPhone.

I am using JavaScript ion.sound.play("beep") this function to play the sound. I have kept the sound file in my folder. Can any one help me out; how can I play sound on iPhone using JavaScript?

The sounds require user input in iOS9. You can initialize the sound with an "invisible" button that disappears after one press at the initialization of your app. Once triggered, you should be able to call ion.sound.play("beep") programatically. I will help You.

CSS:

<style>
    #init {
        position: absolute;
        margin-right: 0px;
        margin-left: 0px;
        margin-top: 0px;
        margin-bottom: 0px;
        z-index: 1000;
    }
</style>

JAVASCRIPT:

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {

    document.write('<a id="init" ontouchstart="javascript:sndInit();"></a>');

    function sndInit(){
    ion.sound.play("beep");
    ion.sound.pause("beep");
    document.getElementById('init').style.display = 'none';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM