Audio in Android

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sjennings
Posts: 7
Joined: Sat Nov 05, 2011 8:35 pm

Audio in Android

Post by sjennings » Sat Nov 05, 2011 8:38 pm

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.

saintyboy
Posts: 6
Joined: Sat Aug 27, 2011 1:22 am

Re: Audio in Android

Post by saintyboy » Mon Nov 07, 2011 12:54 am

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

sjennings
Posts: 7
Joined: Sat Nov 05, 2011 8:35 pm

Re: Audio in Android

Post by sjennings » Mon Nov 07, 2011 3:13 am

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Audio in Android

Post by jacque » Mon Nov 07, 2011 6:26 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sjennings
Posts: 7
Joined: Sat Nov 05, 2011 8:35 pm

Re: Audio in Android

Post by sjennings » Tue Nov 08, 2011 4:56 am

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?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Audio in Android

Post by jacque » Tue Nov 08, 2011 9:34 am

Can we see your script?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sjennings
Posts: 7
Joined: Sat Nov 05, 2011 8:35 pm

Re: Audio in Android

Post by sjennings » Tue Nov 08, 2011 10:20 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Audio in Android

Post by jacque » Tue Nov 08, 2011 11:17 pm

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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

saintyboy
Posts: 6
Joined: Sat Aug 27, 2011 1:22 am

Re: Audio in Android

Post by saintyboy » Sat Nov 12, 2011 2:24 am

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Audio in Android

Post by jacque » Sat Nov 12, 2011 2:52 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply