Playing Audio on Scene Load


(Matt) #1

I understand that iOS does not allow playing audio on Scene Load. However, I have a document where audio is set to play onScene load on each of several scenes. I have a persistent symbol for navigation, where there are arrows moving each scene left and right as well as numbers that represent each scene for the user to jump around to the various scenes.

When the user shifts through each scene using the arrows the audio does not play on scene load. If the user taps one of the numbers to jump to a scene the audio plays when the scene loads. After doing this the audio plays on each scene load when the user uses the arrows to scroll to each scene.

What is going on here? Is there a way I can get the audio to play on scene load using the arrows. without the user first using the number to jump to a scene? The file is too large to share here.


#2

Audio will play on scene load if the touch action that triggers it occurs within about 100ms. If you have a transition (after tap and before the ‘scene load’) that increases this delay, iOS will assume you didn’t mean for audio to start blaring out of your device.

Does the audio play for you on desktop browsers?


(Matt) #3

Thanks Daniel.
So if I began the experience with a scene that simple said, “Click Here To Begin” and then it transitioned to the next with audio onSceneload that should work in theory…? Any other recommendations?

Everything works as expected in a browser

Thank you!


#4

That should work for you – Hype will preload audio elements if you have ‘preload’ checked (by default). Test it out and let me know if you see (or hear) any issue.

You may run into issues if you have several audio elements preloaded, especially on slower mobile devices.


(Matt) #5

Ok, thank you. I guess my question (I think I know the answer to) is there any way to have audio begin without the user having to do anything?

thanks
Matt


#6

Only if they’ve installed your app from the app store. (This is a restriction in Mobile Safari)


#7

I have an interactive childrens book where I have this huge Start button at the beginning of the the book. This button triggers an audio file (I guess this could be just one second of silence, but I have this Pling going), and starts the book. The user don´t see this as an “play audio” action, just a start button. The rest of the book plays audio as it should after this start button :slight_smile:


(Lucky) #8

What if, and I’m sidetracking a bit here you want a secondary audio to hit after the first one with a delay or a condition. I had cases in hype where i had onPress = trigger audio with function which worked great. But then i did onPress IF x = y THEN play audio. As soon as it had the if statement the audio refused to play. I was wondering if you’ve ever tried making any hacks or ways around playing multiple audio tracks or a sequence with a single button click. Thanks!


(Jonathan Deutsch) #9

The general hack is that you’d make a Web Audio API buffer and keep it open, feeding data whenever you needed to play something. I’m not sure about the battery impact on this, and it isn’t simple JavaScript (nor would it work in every context since the Web Audio API isn’t supported by all browsers yet).

If you wanted to use the HTML5 audio tag you might be able to use one big audio file and then seek around and play once it has already played once. That’s just a guess though!