Page 1 of 1

Inserting sounds Programmatically

Posted: Tue Mar 24, 2009 7:00 pm
by haitham
Hi,

I want the user to click on a button, browse his/her files and select a specific sound file (WAV file). Then, I want to store the binary data of that sound in a variable (something similar to imageData for images).

How can I do that?

Thanks,
Haitham

Posted: Tue Mar 24, 2009 8:57 pm
by Mark
Dear Haitham,

This is easy.

Code: Select all

answer file "Select a sound file"
if it is not empty then
  put url ("binfile:" & it) into myData
  -- do with myData whatever you like here
end if
Why do you want to do this?

Best,

Mark

Posted: Wed Mar 25, 2009 2:34 pm
by haitham
First, I have to thank you for your help.

Regarding you question, why do I want to do this.

Well, this might need some explanation. In short, the sound will be stored in a database file (SQLite file) in a binary format so that it can be played later directly from ANOTHER application.

Thus, I will ask another question.
Can I use quick time player, or any other things, to play the sound (which is already stored in a binary format)?

If there is no direct way, can I for example create a temp. file on the hard-drive, play it, then delete it?

Hope my question is clear.

Thanks,
Haitham

Posted: Wed Mar 25, 2009 2:48 pm
by Mark
Hi Haitham,

You can't set the sound data of a player object directly. You must have a file first and then set the filename of the player object. Some formats, such as wav and aiff, can be imported into your stack and the data of a video or audio clip can be written to a variable or file directly.

Code: Select all

put the text of audioClip 1 into myVar
put myVar into url "binfile:~/desktop/test.wav"
This works with clips only, not with players.

Best,

Mark

Load audio into player from another button

Posted: Wed May 20, 2009 1:23 pm
by bidgeeman
Is there a way to load an audio clip into a player from another button?

Thanks
Bidge

Posted: Wed May 20, 2009 2:04 pm
by bn
Bidge,

a player and an audioclip are different beasts.

An audioclip you load into the stack and then you play an audioclip (only wav, aiff, au) Useful for short clips that you want to stay in your stack.

a player plays a file on the hardisk. All the formats Quicktime supports.

You load a player with

Code: Select all

set the filename of player "xyz" to "/the/Path/to/my/file/myAudio.mp3"
you can put this into a button of course. Either you take the path from a list of pathes you generated before, or you let the user choose the file.

regards
Bernd

Posted: Wed May 20, 2009 2:15 pm
by bidgeeman
Thanks once again Bernd.

I have been trying for hours to figure out how to get a button to load an mp3 into a player and start it. None of these work.

on mouseUp
load "purge.mp3" into player "Player"
--load audioClip "C:\purge.mp3"
--load "purge.mp3"into player"Player"
start player "Player"
end mouseUp

:(
Cheers
Bidge

Posted: Wed May 20, 2009 2:47 pm
by bidgeeman
Ahh....got it finally.Sorry for all these newbie posts. I'm slowly learning thanks to you all :)

Cheers
Bidge