Page 1 of 1

Playing a wav on ios

Posted: Fri Feb 27, 2015 3:13 pm
by neomodus
Hi
I am trying to play a wav on an iphone when I fire a bullet in a game.
I have added the Laser2.wav to the standalone application 'copy files' area and the application compiles and deploys OK

I have the code below

command fireDart
local tSound
set the itemDelimiter to "/"
put item 1 to -2 of the filename of this stack into tSound
play tSound & "/Laser2.wav"
Put the loc of button"Malien1" into alienpos
if not exists(button "buttonShot") then
clone the button "shotTemplate"
set the name of the last button to "buttonShot"
end if
set the loc of button "buttonShot" to alienpos
put false into fireable
end fireDart

I have also tried
Play specialFolderPath("engine") & "/Laser2.wav"

In both cases the path seems correct but when I fire the bullet the sound doesn't play, the bullet fires and I am then completely thrown out of the application running on the iphone.

The exact same code works fine on the MAC.
If I take the sound playing element of the code out it works fine on the iphone but clearly no sound.
I am using the latest version of Livecode
Any suggestions please?

Re: Playing a wav on ios

Posted: Fri Feb 27, 2015 3:26 pm
by Klaus
Hi neomodus,

ALWAYS use parens when concatenating path- and object names in Livecode,
EVEN if it might work without them from time to time!
Don't rely on this! EVER! 8)

This should work:
...
play (tSound & "/Laser2.wav")
...
Hint: If you "fire" this from a SUBSTACK, use this:
...
set the itemDelimiter to "/"
put item 1 to -2 of the EFFECTIVE filename of this stack into tSound
play (tSound & "/Laser2.wav")
...

Best

Klaus

Re: Playing a wav on ios

Posted: Fri Feb 27, 2015 4:44 pm
by neomodus
Hi Klaus
I have tried your suggestion but I am getting exactly the same issue. No sound and I get thrown out the application. Have you any other thoughts please?

Re: Playing a wav on ios

Posted: Fri Feb 27, 2015 4:52 pm
by Klaus
Hi neomodus,

hm, maybe iOS doesn't like WAV files?
Never worked with sound on iOS, so please try an AIF or MP3 file.


Best

Klaus

Re: Playing a wav on ios

Posted: Fri Feb 27, 2015 7:19 pm
by neomodus
Hi Klaus
I get the same problem regardless of the audio file format

Re: Playing a wav on ios

Posted: Fri Feb 27, 2015 7:37 pm
by Klaus
Hmmmmm?

The iOS filesystem is case-sensitive, but you surely did check for the correct filename a couple of times, right?
laser2.wav <> Laser2.wav

Sorry, out of brilliant ideas in the moment...

Oh, wait, you could check for a possible cause by adding this line:
...
play (...)
answer the result
## Should be empty on success and may give a hint if it fails!
...

Re: Playing a wav on ios

Posted: Mon Mar 02, 2015 7:00 pm
by neomodus
Hi Klaus
It returns empty then just throws me out.

Re: Playing a wav on ios

Posted: Mon Mar 02, 2015 7:05 pm
by Klaus
Hmmm, sorry, out of brilliant ideas in the moment...

Oh, did you try to play the file using -> mobilePlaySoundOnChannel?

Re: Playing a wav on ios

Posted: Fri Mar 06, 2015 9:46 pm
by neomodus
Hi Klaus
The sound now works absolutely fine using mobilePlaySoundOnChannel when I test it on my old Ipad 2 using IOS 8.1.3 but I get no sound on an Iphone running IOS 6.1.6 even though the game works and it no longer throws me out of the application.

I have standalone application settings set to 6.1 or later in Livecode and am using the latest release of Livecode.
Thanks so much for your advice.
Any further suggestions please?

Re: Playing a wav on ios

Posted: Fri Mar 06, 2015 11:13 pm
by Simon
Hi neomodus,
There was someone else who had a problem here on iOS. Test using a headset.
Apparently there is some setting on the iPhone that controls this.
Or maybe there is a particular CODEC setting in the wav file (bit-rate and so on).

Simon

Re: Playing a wav on ios

Posted: Sat Mar 07, 2015 12:35 am
by neomodus
Thanks so much for that. To my amazement it worked fine through earphones on the Iphone. Then my son showed me a switch that to my embarrassment solves the problem through the speakers! :D

Re: Playing a wav on ios

Posted: Sat Mar 07, 2015 2:57 am
by Simon
Hi neomodus,
...switch that to my embarrassment solves the problem...
Since you are at least the second person that has had problems with this, could you describe where this switch is on the iPhone? Will save others time.

Simon