Advice on using iphonePlaySoundonChannel
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Advice on using iphonePlaySoundonChannel
Can anyone offer any tips on how to use this function i.e a snippet of code to play say a Wav file.
There is very little in the form of guidance anywhere on this and i cannot get it to work without
a 'can't find handler' error.
There is very little in the form of guidance anywhere on this and i cannot get it to work without
a 'can't find handler' error.
Re: Advice on using iphonePlaySoundonChannel
That command is only recognized while running an iOS app, and it will fail in the IDE. The only way to test it is in the simulator or on a real device. You can branch your code if you want to hear sounds in the IDE during development:
The example assumes that the card has an (invisible) player object, and that the default folder has been set to the one containing your sound files. There are other ways to specify the sound file paths without setting the default folder; you can include the complete path in the sound name, for instance. On iOS, the path must be relative to specialFolderPath("engine"). In the IDE, it will be somewhere on your hard drive, perhaps relative to your stack location.
Let us know if you need more info.
Code: Select all
if the environment = "mobile" then
iPhonePlaySoundOnChannel "mysound.wav","sounds","now"
else -- IDE
set the filename of player 1 to "mysound.wav"
start player 1
end if
Let us know if you need more info.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Advice on using iphonePlaySoundonChannel
Thanks for taking the time to reply and your idea of branching code is a good one except that i am using the iPhonePlaySound function because i need multiple sounds and queued sounds so it wouldnt really work.
However, i cannot get it to work in the simulator either so i'm thinking it could be a path issue though i am using the specialFolder statement when trying to play the sound.
If i've imported the audio file 'yellow.CAF' both as a control and also in the standalone application settings why shouldn't the following code work in the ipad simulator?
put specialFolderPath("engine") & "yellow.CAF" into tsoundfile
iPhonePlaySoundOnChannel tsoundfile,"sounds","now"
However, i cannot get it to work in the simulator either so i'm thinking it could be a path issue though i am using the specialFolder statement when trying to play the sound.
If i've imported the audio file 'yellow.CAF' both as a control and also in the standalone application settings why shouldn't the following code work in the ipad simulator?
put specialFolderPath("engine") & "yellow.CAF" into tsoundfile
iPhonePlaySoundOnChannel tsoundfile,"sounds","now"
Re: Advice on using iphonePlaySoundonChannel
Hi...
I haven't tried this with a file of type CAF, but with an .aiff file there is not a problem...
There is a problem with your script, as you are missing a delimiter in the filepath
Try...
be well
Dixie
I haven't tried this with a file of type CAF, but with an .aiff file there is not a problem...
There is a problem with your script, as you are missing a delimiter in the filepath
Try...
Code: Select all
put specialFolderPath("engine") & slash & "yellow.CAF" into tsoundfile
iPhonePlaySoundOnChannel tsoundfile,"sounds","now"
Dixie
Re: Advice on using iphonePlaySoundonChannel
Thanks Dixie, i have tried aiff files too but get the same problem. I ran the code below using the missing delimiter and the play command works in IDE but not the iphonePlaySoundOnChannel - this ties in with what Jacque was saying about that command failing in IDE. So i test the same code in an ipad simulator and get no sound from either function - could this be something to do with my set up - am i missing some necessary plug-in maybe - all other functions work in the simulator ok - runrev have said they will put a tutorial on the iphonePlaySoundOnChannel command soon but this is really holding up my workflow - if anyone can offer any other advice it would be much appreciated.
on mouseUp
//play specialFolderPath("engine") & slash & "tester.aiff"
play "yellow.CAF"
//iphonePlaySoundOnChannel "Newproject/sounds/yellow.CAF", "new", "now"
put specialFolderPath("engine") & slash & "yellow.CAF" into tsoundfile
//iphonePlaySoundOnChannel "/yellow.CAF", "colour", "now"
iphonePlaySoundOnChannel tsoundfile, "colour", "now"
end mouseUp
on mouseUp
//play specialFolderPath("engine") & slash & "tester.aiff"
play "yellow.CAF"
//iphonePlaySoundOnChannel "Newproject/sounds/yellow.CAF", "new", "now"
put specialFolderPath("engine") & slash & "yellow.CAF" into tsoundfile
//iphonePlaySoundOnChannel "/yellow.CAF", "colour", "now"
iphonePlaySoundOnChannel tsoundfile, "colour", "now"
end mouseUp
Re: Advice on using iphonePlaySoundonChannel
Hi...
No, you are not missing a plug-in... I think that you have a filepath problem.
I have attached a stack that plays a (very badly recorded aif file) in both the IDE and on the iphone simulator. I put the handlers in the stack script for you to look at...
hope it helps
Dixie
No, you are not missing a plug-in... I think that you have a filepath problem.
I have attached a stack that plays a (very badly recorded aif file) in both the IDE and on the iphone simulator. I put the handlers in the stack script for you to look at...
hope it helps
Dixie
- Attachments
-
- soundTest.zip
- (38.78 KiB) Downloaded 253 times
Re: Advice on using iphonePlaySoundonChannel
Which simulator are you using? I couldn't get any sound on it either until I upgraded to the newest. I think it was the 3.2 simulator that wouldn't make a peep. The sounds did work on a real i-device though.
Take out the double slashes in your script too, the compiler may choke on those. It may be aborting with a silent error.
Try this in the simulator:
on mouseUp
put specialFolderPath("engine") & slash & "yellow.CAF" into tsoundfile
iphonePlaySoundOnChannel tsoundfile, "colour", "now"
end mouseUp
Take out the double slashes in your script too, the compiler may choke on those. It may be aborting with a silent error.
Try this in the simulator:
on mouseUp
put specialFolderPath("engine") & slash & "yellow.CAF" into tsoundfile
iphonePlaySoundOnChannel tsoundfile, "colour", "now"
end mouseUp
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Advice on using iphonePlaySoundonChannel
Jacque - changing the simulator had no effect but you were correct Dixie, it was a filepath problem and it came to light by testing your attached stack which coincided with the release of the nice new runrev tutorial on how to use the command.
It was a bit of a 'Doh' moment really - i had not been storing my files in the same folder as the mainstack file and had wrongly assumed that copying them in the standalone application settings would suffice.
All sorted now an thank you both for taking the time to advise me.
It was a bit of a 'Doh' moment really - i had not been storing my files in the same folder as the mainstack file and had wrongly assumed that copying them in the standalone application settings would suffice.
All sorted now an thank you both for taking the time to advise me.