Simulating touch to workaround iOS sound problem

Get help using Construct 2

Post » Fri Nov 27, 2015 11:55 am

I'm making a point and click adventure, and the fact that audio doesn't play on ios until the first touch in every scene is a big problem.

@Ashley suggests in the iOS article "Audio won't play until the first touch. However, this is not usually very important and can be easily worked around with a "touch to begin" screen that plays a sound when you touch it."

In a game with few scenes this wouldn't be a huge problem, but as my game involves players moving from scene to scene, having a sign saying 'touch to start' whenever a player walks from the bathroom to the hall for example would massively break immersion.

I'm wondering: Is there any way touch can be simulated in c2, be it natively or through an addon, and why is a first touch required?
B
11
S
3
Posts: 135
Reputation: 1,309

Post » Fri Nov 27, 2015 12:09 pm

Simulating a physical touch through programming, sounds to me like a hackers dream, so I hope it's not possible..

Why a first touch is needed?

From the manual on audio:

Mobile limitations

Safari on iOS and Chrome for Android share a limitation in playing music. While sound effects can be played at any time, music is only allowed to start playing when the user touches the screen. This is a limitation in the browsers themselves. As a result, if you play music on the start of layout, you may find in these browsers it does not actually start until the next touch.

Safari on iOS has a further limitation that no audio can play at all until the first touch. In other words, audio starts off muted and the first touch unmutes audio playback.

Usually you do not need to handle this in your events. If you try to play sound or music on 'start of layout', the audio object will automatically queue it up for playback the next time the user touches the screen. However you should be aware of this when designing your game. If the first touch changes layout or stops the music, then the music may never be heard. You may want to start playback then encourage the user to touch the screen with a 'Play' icon or something similar.


So it's the browser that has the limitation..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Nov 27, 2015 12:17 pm

Thanks for the info, that's a pain but it sounds like there is very little I can do, aside from hoping someone comes along with a simulate touch plugin, which as you said may be impossible due to security implications :/
B
11
S
3
Posts: 135
Reputation: 1,309

Post » Fri Nov 27, 2015 12:24 pm

Not sure about this, but would starting the music for the next layout on the previous one work?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Nov 27, 2015 12:48 pm

I'm not entirely sure, I'll give a try and report back.
B
11
S
3
Posts: 135
Reputation: 1,309

Post » Fri Nov 27, 2015 12:52 pm

If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.
Scirra Founder
B
395
S
233
G
88
Posts: 24,376
Reputation: 193,842

Post » Fri Nov 27, 2015 2:57 pm

Ashley wrote:If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.

But why does iOS have this limitation? What's the reason? Are they planning to remove it?
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Mon Dec 07, 2015 6:07 pm

Ashley wrote:If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.


Damn, that's an annoying limitation. Sadly I think it will be quite noticeable as in a point and click music really needs to start as soon as you enter the scene to set the atmosphere, and a lot of the scenes start with cutscenes, so they player will have no need to tap the screen for a while :cry:

Guess I'll have to think of something, thanks for clearing it up.
B
11
S
3
Posts: 135
Reputation: 1,309

Post » Mon Feb 22, 2016 6:30 pm

Interesting stuff. I have the same problem on iOS (cocoon.io) but not with sound. I have the same with localstorage. sometimes it loads my saved variables instantly and sometimes I need to touch the screen and then it loads up.

Anyone else hat this? On Browser preview all works fine.
Working on "EVERBLAST"
Image
B
31
S
6
Posts: 221
Reputation: 2,837


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], JDebstup and 15 guests