Home › Forums › Programming › Audio on IOS
- This topic has 6 replies, 2 voices, and was last updated 7 years ago by
adcornetto.
-
AuthorPosts
-
2018-11-13 at 7:00 pm #8889
adcornetto
CustomerI 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);
2018-11-14 at 7:34 am #8901
Yuri KovelenovStaffHi,
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.2018-11-14 at 1:50 pm #8904adcornetto
CustomerI 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?
2018-11-14 at 2:05 pm #8906
Yuri KovelenovStaff2018-11-14 at 9:52 pm #8908adcornetto
CustomerIt 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.2018-11-15 at 7:47 am #8909
Yuri KovelenovStaffYes, 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.
2018-11-15 at 9:32 pm #8914adcornetto
CustomerThanks. That was what I was trying to setup.
-
AuthorPosts
- You must be logged in to reply to this topic.
