We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Audio on IOS

Home Forums Programming Audio on IOS

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #8889
    adcornetto
    Customer

    I created an app with audio that works great on the desktop, but the audio will not play in safari on my iphone. I tried a recommendation that I found online to “unlock” audio in html5 / webgl by adding the following to the .js file, but no luck. Any ideas?

    window.addEventListener(‘touchstart’, function() {

    // create empty buffer
    var buffer = myContext.createBuffer(1, 1, 22050);
    var source = myContext.createBufferSource();
    source.buffer = buffer;

    // connect to output (your speakers)
    source.connect(myContext.destination);

    // play the file
    source.noteOn(0);

    }, false);

    #8901

    Hi,

    This code snippet uses Web Audio API which may have compatibility problems. Why don’t you use Sound Puzzles instead that work on top of vanilla HTML5?
    Look in the puzzles for the Spinner demo, for example.

    Chief 3D Verger | LinkedIn | Twitter

    #8904
    adcornetto
    Customer

    I used sound puzzles first and that did not work. I was trying to find a fix. Is there a modification to the audio function in the visual_logic.js that would detect a touch on an iphone?

    #8906

    What format for sound files do you use? (mp3 is the most widely supported format). Does our Spinner demo produce any audio on your iPhone?

    Chief 3D Verger | LinkedIn | Twitter

    #8908
    adcornetto
    Customer

    It had something to do with the puzzles logic.
    When I had the play sound in the when finished do part of the play animation block it would not work.
    I moved it outside the block and it plays fine. I wanted it to start after the animation played, so I used a time after block. Worked great.
    Thanks again for your help.

    #8909

    Yes, due to security policy on iOS, sounds are only allowed to start playing upon user action (touch).

    There is a trick, however. To overcome this problem, you can use HTML puzzle on event of click with document as target, in order to trigger all your sounds when the user runs an application and touches the screen. Then you can immediately stop all your sounds to prevent cacophony. Afterwards all your sounds will be available for playing at arbitrary time just like on desktop.

    See the Puzzles under the Sound tab in our Industrial robot demo for an example.

    Chief 3D Verger | LinkedIn | Twitter

    #8914
    adcornetto
    Customer

    Thanks. That was what I was trying to setup.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.