Page 1 of 1

Selecting and playing a sound file in iOS?

Posted: Tue Nov 08, 2011 8:10 am
by grovecat
I can use the iTunes file sharing facility to copy mp3 files into the Documents folder of my app, and display them in a scrolling list field (on the iPad, not the simulator). And I can select one of them but I'm puzzled on how to play the selected file. There does not seem to be any explanation on how to do this in the manual or in any of the other places I have looked.

Could some kind person please point me in the right direction?

TIA

Re: Selecting and playing a sound file in iOS?

Posted: Wed Nov 09, 2011 4:34 pm
by Mark
Hi Tia,

Does

Code: Select all

play "path/to/file.mp3"
work? You can retrieve the path with e.g.

Code: Select all

set the itemDel to slash
put (item 1 to -2 of the effective filename of this stack & "/file.mp3") into myPath
Kind regards,

Mark

Re: Selecting and playing a sound file in iOS?

Posted: Wed Nov 09, 2011 5:12 pm
by Klaus
Hi grovecat,

you can access the DOCUMENTS folder on iOS via:
specialfolderpath("documents")

And the currently selected text in a list field via:
the selectedtext of me ## if the script is in the field or
the selectedtext of fld "xyz"

Then you can combine both of them:
...
put specialfolderpath("documents") & "/" & the selectedtext of fld "xyz" into tSoundFile
## Now you have the EXACT path to the sound file and you can simply PLAY it:
play tSoundFile
...

You did not find this in the manual since this is just one of the gazillion options to create a path!
Please do also check the "iOS Release Notes" -> Menu: Help! for other available iOS "specialfolderpath"s and more info.
And do it with each new release!

To learn more about LiveCode check these stacks:
http://www.runrev.com/developers/lesson ... nferences/

Best

Klaus

Re: Selecting and playing a sound file in iOS?

Posted: Wed Nov 09, 2011 5:29 pm
by Mark
Hi Klaus,

It is possible to include files in the same folder as the stack (or executable file). This folder isn't always the documents folder. Also, the documents folder is a writable folder and you might feel slightly more comfortable keeping files in a non-writable folder. Moreover, including a documents folder with the stack didn't always work for me (but I haven't figures out whether it is me or LiveCode).

Kind regards,

Mark

Re: Selecting and playing a sound file in iOS?

Posted: Wed Nov 09, 2011 5:36 pm
by Klaus
Hi Mark,

whatever, I only tried to answer grovecats exact question:
How to play a sound which ALREADY resides in the documents folder of his app from its name listed in a list field. 8)


Best

Klaus

Re: Selecting and playing a sound file in iOS?

Posted: Wed Nov 09, 2011 5:41 pm
by Mark
You're right. I overlooked that.

Mark

Re: Selecting and playing a sound file in iOS?

Posted: Thu Nov 10, 2011 1:04 am
by grovecat
Thanks Klaus

That is exactly what I needed.

Don

Re: Selecting and playing a sound file in iOS?

Posted: Thu Nov 10, 2011 11:37 am
by Klaus
Hi Don,

I know :D


Best

Klaus