Sound playback driving me crazy...

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Sound playback driving me crazy...

Post by dalkin » Fri Mar 11, 2011 10:09 pm

Hi folks,

Is there any way you can see to download a file from a URL into either "tmp" or "cache" that would allow specialFolderPATH("tmp") or specialFolderPATH("cache") to be called in this instance? I've been trying with the getResource function but can't seem to get it to work.
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

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

Re: Sound playback driving me crazy...

Post by Klaus » Sat Mar 12, 2011 5:40 pm

Hi dalkin,
dalkin wrote:... Is there any way you can see to download a file from a URL into either "tmp" or "cache...
OK, no problem so far...
dalkin wrote:... that would allow specialFolderPATH("tmp") or specialFolderPATH("cache") to be called in this instance?
???
dalkin wrote:I've been trying with the getResource function but can't seem to get it to work.
"getResource" is something completely different, a shadow from the past (of Mac OS), so to say :D

Sorry, don't have the slightest idea of what you are trying to do...? 8)

dalkin
Posts: 183
Joined: Wed Jul 04, 2007 2:32 am
Contact:

Re: Sound playback driving me crazy...

Post by dalkin » Sat Mar 12, 2011 11:47 pm

LOL Klaus! You're not half as confused as I am. You're right, I don't know exactly what I want. The project is, in a sense, to make an MP3 player, except in this case, it'll be poetry readings, not music. When I first started the project, the client (my wife in this case - the pay's lousy but the conditions are terrific sort-of-thing) wanted an app that would play a new poem every day. I was originally experimenting with MOV files because there might be instances of an actual video of a poetry reading. At that stage, it was never an option to bundle the movie files with the app but to simply hard-code a button that fetched a URL. That quickly turned into a logistical nightmare because while I could play a file easily enough, and return the text of the track, and information about the poet, into a text field with:

Code: Select all

on openCard
play video "http://www.myURL.com.au/poems/poem1.mov"
set the visible of button "Read this poem" to true
 put empty into field "Title"
end openCard

on movieTouched
   play stop
   hide the templatePlayer
end movieTouched
and with a button:

Code: Select all

on mousedown
   put empty into field "Title"
   put URL "http://www.myURL.com.au/poems/poem1.txt" into field "Title" 
   set the visible of button "Read this poem" to false
end mousedown
I couldn't figure out a way, on a daily basis, to rotate the files on the server. I looked at AppleScript, which only went so far, and a friend of a friend suggested I use "push notification" technology but that involved XCode and C++ - Heather told me that "Thank you for your request. Its in the consideration set. Whether/when it will be implemented I cannot yet comment on."

So THEN I abandoned the movie idea and looked at MP3, mainly from the POV of file size. Again, if I bundle the MP3s with the app, I don't quite understand how a user can have access to fresh content, so I started exploring the idea of downloading an MP3 from the web, putting it into a cache or temporary file, and having the app retrieve the current content list. Which led me to this thread and it appears it can't be done. The iOS release notes state:
However, it is important to be aware that the iPhoneOS imposes strict controls over what you can
and cannot access. Each application in iPhoneOS is stored in its own 'sandbox' folder (referred to as
the home folder. An application is free to read and write files within this folder and its descendants,
but is not allowed to access anything outside of this
.
When an application is installed on a phone (or in the simulator) a number of initial folders are
created for use by the application. You can locate the paths to these folders using the
specialFolderPath() function with the following selectors:
• home – the (unique) folder containing the application bundle and its associated data and
folders
• documents – the folder in which the application should store any document data (this folder
is backed up by iTunes on sync)
• cache – the folder in which the application should store any transient data that needs to be
preserved between launches (this folder is not backed up by iTunes on sync)
• temporary – the folder in which the application should store any temporary data that is not
needed between launches (this folder is not backed up by iTunes on sync)
• engine – the folder containing the built standalone engine (i.e. the bundle). This is useful for
constructing paths to resources that have been copied into the bundle at build time.
In general you should only create files within the documents, cache, and temporary folders. Indeed,
be careful not to change or add any files within the application bundle. The application bundle is
digitally signed when it is built, and any changes to it after this point will invalidate the signature
and prevent it from launching.
so I guess one part of my search for a solution was looking for a way to download files to the specialFolderPath ("cache") folder that seems to be automatically created when the app is built. In the absence of anything fancy, I guess my fallback position is for a simple MP3 player where MP3s are bundled with the app and updates are issued every few months.

Thanks for taking the time to read this.
The underlying purpose of Al is to allow wealth to access skill
while removing from the skilled the ability to access wealth.

hliljegren
Posts: 111
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: Sound playback driving me crazy...

Post by hliljegren » Sun Mar 13, 2011 4:59 pm

Hi dalkin!

You don't have to rotate files on the server you could instead "rotate" the URL in your app

Code: Select all

put the date into pDate
convert pDate to dateItems
put "http://www.myURL.com.au/poems/poem" & item 1 of pDate & "_" & item 2 of pDate & "_" & item 3 of pDate & ".mov" into pURL
play video pURL
...
But you need to handle the case that there might be a day when there isn't a new poem. I would instead suggest that you load a link to the latest poem (if you don't want to tinker with a database backend).

Create a file called latestpoem.txt (or something) which you store on your server. The only content needed in that file could be a link to your latest poem:

Code: Select all

http://www.myURL.com.au/poems/poem123.mov
Then you can load the "link" first and then play your latest poem

Code: Select all

put URL "http://www.myURL.com.au/poems/latestpoem.txt" into pURL
play video pURL
The only thing you need to do is to add your poem to your server and then change the "link-file", which you of course use LiveCode to handle ;)

There should be nothing stopping you from downloading the poem to the cache, tmp or ever the documents directory but I see no point except from being able to play files off-line.
:-Håkan
___________________________________
MacBook Pro M1 MAX 64 Gb,
LiveCode 10.0.1rc3

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Sun Mar 27, 2011 2:23 am

This is the post i've been looking for. Everything is working on the build but I can't seem to get it to work on my iPod. I put the path from my desktop to the game and it plays but I don't know how to "attach" it to the game file. I tried file -> import as control -> audio file. I don't know how to get it into the "engine" folder of my game and play it when needed. I know that you use the

Code: Select all

specialFolderPath("engine")
and then the path but maybe when I get it attached to my game it will be different.

Thanks,

Danny

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Sun Mar 27, 2011 9:42 am

Hi Danny,

you can add a file or a folder by specifying that in Standalone Application Settings.
standalone-application-settings.png
standalone-application-settings.png (55.94 KiB) Viewed 9053 times
It will be bundled with your app when you build it and it is in the "engine" folder.

From there you can access your file or Folder/files. Remember that pathes are case sensitive in iOS.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Sun Mar 27, 2011 1:31 pm

Thanks Bernd! I added that but it didn't play on my iPod. Now the only thing is the path of the file goes something like this /Users/danny/Desktop/Bite.aif
I use this on the computer and it works fine but I feel like it isn't able to reference it on my iPod because the file is on my desktop. I saw some talk about subdirectories and I was wondering if you could explain how those work and how to get the sound into one of them. I thought that it might work because it would reference the sound located on the app and not my desktop.

Thanks

Danny

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Sun Mar 27, 2011 2:30 pm

Hi Danny,

I made a little stack with a sound file in a folder. Please add the folder in the Standalone Application Setup as shown. The current path in the Standalone Application Setup will not work since it is my path.
I chose a mix of lower and uppercase names. This is often a cause of problems when setting up paths. And don't forget a slash before your folder and filename.
SpecialfolderPath returns a folder name but if you append further elements you have to prepend them with a slash. See the script.
Tested in the simulator and works.

Kind regards

Bernd
Attachments
play audio.zip
(69.17 KiB) Downloaded 317 times

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Mon Mar 28, 2011 2:36 am

Bernd, please don't think of me as PATHetic I've really been trying to get this to work on my iPod but I just haven't been able to :( . The program did help me to understand more but I just don't know why it won't work. I've posted some screen shots of my code. I tried to stay as close to your code as possible because I know it works.
I made a folder on my desktop and put the .aif file in there and went to live code and clicked copy files then add file and also folder (never two files in the box) just to see if that would get it to work.

Danny
Attachments
Screen shot 2011-03-27 at 9.35.13 PM.png
Screen shot 2011-03-27 at 9.35.13 PM.png (15.05 KiB) Viewed 9035 times
Screen shot 2011-03-27 at 9.21.11 PM.png
Screen shot 2011-03-27 at 9.21.11 PM.png (13.84 KiB) Viewed 9035 times
Screen shot 2011-03-27 at 9.20.26 PM.png
Screen shot 2011-03-27 at 9.20.26 PM.png (12.95 KiB) Viewed 9035 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Mon Mar 28, 2011 10:11 am

Hi Danny,

well now I think it is a problem of the audio format you are trying to use. I just attempted to play an .aif in the simulator and it did not work.

Try to convert your aif to an iPhone compatible format. To do so you can open the Quicktime Player X (the new one in OSX) that is the standard player and under File -> Export as -> Format -> iPhone.

Did my example stack work for you with the sound file I provided?

Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Mar 30, 2011 6:55 pm

Bernd,

Thank you so much for helping all us noobs. I don't know where you find the time.

Your little app worked for me in the simulator, but not in LC. How do I set up the paths so that they work in both? I've been trying to put all my sound files in the defaultFolder, and have been using only relative path names, so all this "engine" business is new to me.

Cheers,

Britt

Edit: When I changed your file to a .wav file, it worked in LC, but not in the sim. When I changed it to a .m4v or .3gp file, it worked in the sim, but not in LC.
Last edited by Brittgriscom on Wed Mar 30, 2011 7:41 pm, edited 1 time in total.

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

Re: Sound playback driving me crazy...

Post by Klaus » Wed Mar 30, 2011 7:28 pm

Hi Britt,

I have no problems with MP3 audio files!
Work fine in the Simulator (and device, of course)!


Best

Klaus

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Mar 30, 2011 7:43 pm

Can QT convert files to mp3 files, or do I have to use GarageBand for that?

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Mar 30, 2011 7:49 pm

This worked in the sim, but not in LC. What am I missing?

on mouseUp
put specialFolderPath("engine") & "/soundFolder/page1.mp3" into tWholePath
play tWholePath
end mouseUp

Edit: This worked for a .wav file in the sim too, but, again, not in LC.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Wed Mar 30, 2011 8:00 pm

Hi Britt,

I think iTunes can export non-protected files to mp3.

The problem is that the command play in Lc can only use a very restricted number of formats. A player object in LC can play anything that Quicktime supports on a Mac.

One way to play a sound file in iOS and LC is to change the code I provided in above sample.

You would have to add a player object and name it "p1" to the card.

the code of the button "playImbeddedAudio" would be:

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      play tWholePath
   else
      put the effective fileName of this stack into tWholePath
      set the itemdelimiter to "/" 
      put  "/soundFolder/samoashort.3gp" into last item of tWholePath
      set the filename of player "p1" to tWholePath
      start player "p1"
   end if
end mouseUp
the code of the button "stopPlay" would be:

Code: Select all

on mouseUp
   if the environment is "mobile" then
      play empty
   else
      stop player "p1"
end if
end mouseUp
this assumes the folder is at the same level as the stack that is using the folder, like in the sample zip.

Of course it would be easier as Klaus said to find a format that plays in both, LC and simulator/devices. But you would still have the problem of the paths. see above for that.

kind regards
Bernd

Post Reply