Inserting sounds Programmatically

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
haitham
Posts: 6
Joined: Fri Dec 19, 2008 7:47 pm

Inserting sounds Programmatically

Post by haitham » Tue Mar 24, 2009 7:00 pm

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

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

Post by Mark » Tue Mar 24, 2009 8:57 pm

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
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

haitham
Posts: 6
Joined: Fri Dec 19, 2008 7:47 pm

Post by haitham » Wed Mar 25, 2009 2:34 pm

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

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

Post by Mark » Wed Mar 25, 2009 2:48 pm

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
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

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Load audio into player from another button

Post by bidgeeman » Wed May 20, 2009 1:23 pm

Is there a way to load an audio clip into a player from another button?

Thanks
Bidge

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

Post by bn » Wed May 20, 2009 2:04 pm

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

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Wed May 20, 2009 2:15 pm

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

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Wed May 20, 2009 2:47 pm

Ahh....got it finally.Sorry for all these newbie posts. I'm slowly learning thanks to you all :)

Cheers
Bidge

Post Reply