Selecting and playing a sound file in iOS?

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
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Selecting and playing a sound file in iOS?

Post by grovecat » Tue Nov 08, 2011 8:10 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Mark » Wed Nov 09, 2011 4:34 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Klaus » Wed Nov 09, 2011 5:12 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Mark » Wed Nov 09, 2011 5:29 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Klaus » Wed Nov 09, 2011 5:36 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Mark » Wed Nov 09, 2011 5:41 pm

You're right. I overlooked that.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: Selecting and playing a sound file in iOS?

Post by grovecat » Thu Nov 10, 2011 1:04 am

Thanks Klaus

That is exactly what I needed.

Don

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting and playing a sound file in iOS?

Post by Klaus » Thu Nov 10, 2011 11:37 am

Hi Don,

I know :D


Best

Klaus

Post Reply