Apply two Sounds at the same time LiveCode 8 (RC1)

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
MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Apply two Sounds at the same time LiveCode 8 (RC1)

Post by MarkoSato » Fri Apr 22, 2016 8:03 am

Hello,

In my project I have a background music implemented on preOpenCard which continues over 1-2 cards.
While the music is playing, i wanted to add another sound, for example if I click on a button that it makes a "click" sound effect or an animal sound effect but while the background music is still running.
I tried to implement both the same way with ' play "mySound.wav" ' which i "imported as Control" first of all, but when I click for example on the button the click sounds plays but the background music stops.

Is there a way without extension or anything like that only with raw liveCode to make 2 sounds playing at the same time possible?

(I am currently using LiveCode Community 8 (RC1) on a macbook air.

I Hope you can help me.

Kind Regards
Mark

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

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by Klaus » Fri Apr 22, 2016 10:36 am

Hi Mark,

if in doubt, always take a look at the dictionary!
From the docs about "play..."
....
If you start playing an audio clip when another one is playing, the first audio clip is stopped,
and a playStopped message is sent to the current card. You cannot play two sounds at the same time,
nor can you queue a sound while another sound is playing.

...
So you need to set up two player objects (or maybe only one for your bg music/sound), but these only work
with external files and you need to set their filename property.

This way you can have as many sounds as you like playing at the same time.


Best

Klaus

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by MarkoSato » Fri Apr 22, 2016 11:17 am

Hello,

Oh Ok sorry my bad i am still a newbie.
Hmm that's unfortunate because I am not allowed to use extensions in my project.
Well, can't do anything about it. Thank you anyways. :D

Best Regards
Mark

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

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by Klaus » Fri Apr 22, 2016 11:24 am

Hi Mark,

sorry compeltely forgot this one: Welcome to the forum! :D

What you you mean "no externsions allowed"?

QuickTime (and nowadays AVFoundation) is the underlying multimedia engine of
operation system (!) and LC is only using it, as all other audio/video apps on the Mac do!


Best

Klaus

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by MarkoSato » Fri Apr 22, 2016 2:50 pm

Hey Klaus,

I am a student at university and I have to make a project with LiveCode.
In the script the prof wrote that" we are not allowed to use external links or datas, no substacks and no externals etc".
So because of this I don't want to risk my project to be not evaluated.
(And I also don't know how to use externals etc. :oops: )

Best

Mark

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

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by Klaus » Fri Apr 22, 2016 3:07 pm

Ah, "...no external datas...", I see.
OK, bad luck (and a silly restriction in my opinion, internal or external sounds, what's the difference?) 8)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by jacque » Fri Apr 22, 2016 5:31 pm

You could ask whether including an audio file on disk is considered an external resource. Or you can just work around the problem with a little trick.

Store the raw audio file in a custom property of the stack. When you need to play the audio, write the file to disk in the user's temporary folder. Assign the temp path to the player control and start playback. When the app quits, or whenever you're done with the audio, delete the temporary file.

I've done this in more than one app and it works fine. Ask if you need help with any of the steps. You'll probably need to look at the tempName entry in the dictionary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

theotherbassist
Posts: 115
Joined: Thu Mar 06, 2014 9:29 am

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by theotherbassist » Sun Apr 24, 2016 6:36 pm

And if after pulling your audio from a custom prop you still don't want to use QuickTime, you can always play multiple sounds simultaneously via html and JavaScript in a browser instance.

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Apply two Sounds at the same time LiveCode 8 (RC1)

Post by MarkoSato » Sun Apr 24, 2016 6:55 pm

OK, thank you very much for the help.
I am going to see my prof next week so I will ask him there if I could do it like you suggested.

Best
Mark

Post Reply