Page 1 of 1
Audio in Android
Posted: Sat Nov 05, 2011 8:38 pm
by sjennings
Hi I'm new to live code and was creating an application for my android phone. This application is supposed play sounds when images are touched. I can not figure out how to play audio when the images are touched on the Android because it can not get the sound file. How do I put the sound file in the standalone application and play it from the on mouseUp method? Thanks.
Re: Audio in Android
Posted: Mon Nov 07, 2011 12:54 am
by saintyboy
Hi, i've not used the android implementation but i assume its the same as the ios - you need to copy your files into your standalone by selecting your main stack then goto file on the livecode menu bar and select stand alone application settings and click the copy files tab - then just copy your sound files across. Alternatively you can select import as control from the livecode menu file tab and select audio file. Hope this helps
Re: Audio in Android
Posted: Mon Nov 07, 2011 3:13 am
by sjennings
Thanks for an answer! I have tried that, but sadly it did not work. I've been searching around for the past day looking for a solution but I can't find one.
Re: Audio in Android
Posted: Mon Nov 07, 2011 6:26 am
by jacque
Besides including the files in the standalone "Copy Files" section, you also need to provide a full path to the sound file in your script. This kind of path won't work:
play "mysound.mp3"
You can include your sound files individually, or you can put them into a folder and include the whole folder in the Copy Files pane. In either case, the path has to be relative to the engine. You use "specialFolderPath" to get that:
Code: Select all
put specialFolderPath("engine") & "/mysound.mp3" into tSndPath
play tSndPath
If your sounds are in a folder, just include it in the path:
Code: Select all
put specialFolderPath("engine") & "/soundsFolder/mysound.mp3" into tSndPath
play tSndPath
If you want, you can concatenate those two lines into one. I wrote it the long way for clarity.
Re: Audio in Android
Posted: Tue Nov 08, 2011 4:56 am
by sjennings
I tried it, but it did not work. I put the full path of the sound on my computer and tried the one from Copy files tab. Is there another path I should be looking for?
Re: Audio in Android
Posted: Tue Nov 08, 2011 9:34 am
by jacque
Can we see your script?
Re: Audio in Android
Posted: Tue Nov 08, 2011 10:20 pm
by sjennings
Code: Select all
on mouseUp
put specialFolderPath("engine") & "/Users/name/Dropbox/MusicInventor/clap-q.wav" into tSndPath
play tSndPath
answer "This button works" with "Ok"
end mouseUp
Re: Audio in Android
Posted: Tue Nov 08, 2011 11:17 pm
by jacque
Thanks, that helps. The path you're using only exists on your hard drive and will only work in the IDE. A mobile app doesn't have access to your drive, so you need to use a folder structure inside the app. If your sounds are included individually in the Copy Files pane, then the path is:
specialFolderPath("engine") & "/clap-q.wav"
If you want to hear the sound in the IDE and the Android app both, you have to branch the code:
Code: Select all
if the environment <> "mobile" then -- IDE or desktop app
put "/Users/name/Dropbox/MusicInventor/clap-q.wav" into tSndPath
else -- mobile app
put specialFolderPath("engine") & "/clap-q.wav" into tSndPath
end if
play tSndPath
Re: Audio in Android
Posted: Sat Nov 12, 2011 2:24 am
by saintyboy
Jacque is right - and i also bet that you have made the mistake that i made. You must save your sound files in the same folder as your main stack otherwise you will only here a clicking sound.
Re: Audio in Android
Posted: Sat Nov 12, 2011 2:52 am
by jacque
Or at least they need to be saved somewhere relative to the stack. I usually put the sounds into a sounds folder which is in the same folder as the mainstack. Then I include the whole folder in the Copy Files pane.