play a lot of audio file simultaneously

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
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

play a lot of audio file simultaneously

Post by problème » Sat Nov 28, 2015 12:29 pm

Hello,

I would want to know how to play a lot of audio file simultaneously ? i have a background music and when i press a button a sound is playing but i when i press a button the background music stopped.

Code: Select all

on preOpenCard
 play audioClip "backgroundmusic" looping
en preOpenCard

command WhenIClickOnAButton
 play audioClip "pressButton"
end WhenIClickOnAButton

on CloseCard
 play stop  # stop the background music
end CloseCard

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

Re: play a lot of audio file simultaneously

Post by bn » Sat Nov 28, 2015 1:53 pm

Hi problème,

have you tried to use player objects for your sounds instead of the play audioClip command.

from the dictionary for the play command
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.
see dictionary for "player", 2 player objects can play at the same time.

Kind regards
Bernd

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: play a lot of audio file simultaneously

Post by problème » Sat Nov 28, 2015 2:50 pm

I tried to do this, i can now use 2 audios files simultaneously.

Code: Select all

on preOpenCard
   player1
   player2
   StartPlayer1
end preOpenCard

command player2
   create player "lecteur2"
   put specialFolderPath("ressources") & "/musique/pressButton.wav" into Mentrer
   set the filename of player "lecteur2" to Mentrer
end player2

command player1
   create player "lecteur1"
   put specialFolderPath("ressources") & "/musique/backgroundmusic.wav" into Mmenu
   set the filename of player "lecteur1" to Mmenu
end player1

command StartPlayer1
   start player "lecteur1"
   loop 
end StartPlayer1

command loop
   if (the duration of player "lecteur1" = the currentTime of player "lecteur1") then
      loopPlayer1
   end if
   send "loopPlayer1" to me in 100 milliseconds
end loop

Last edited by problème on Sat Nov 28, 2015 2:56 pm, edited 1 time in total.

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

Re: play a lot of audio file simultaneously

Post by Klaus » Sat Nov 28, 2015 2:56 pm

Just set a property for your "background music" player:

Code: Select all

command player1
   create player "lecteur1"
   set the LOOPING of player "lecteur1" to TRUE
   put specialFolderPath("ressources") & "/musique/backgroundmusic.wav" into Mmenu
   set the filename of player "lecteur1" to Mmenu
end player1
First entry for "loop" in the dictionary! 8)

Any special reason why you always create new objects via script instead of creating them ONCE (manually),
like the player objects here, and just re-use them?

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: play a lot of audio file simultaneously

Post by problème » Sat Nov 28, 2015 3:07 pm

it was for the tests.
i will create my player in the mainstrack script, when i open my application i go to card "home screen" the backgroundmusic start, when i go to card 2 the backgroundmusic continue. But i don't want my players appear

I can't use object player in different card through different card like audioClip.
Last edited by problème on Sat Nov 28, 2015 3:28 pm, edited 1 time in total.

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

Re: play a lot of audio file simultaneously

Post by Klaus » Sat Nov 28, 2015 3:27 pm

To have a player on several cards as you noted, you need to GROUP that player and PLACE that group on all cards where the sound should play.
Then you can hide the player/group!

Of course you can do everything by script, but that's a lot of scripting! :D
So why not prepare your players (create and set all neccessary properties manually) and use them further on?

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

Re: play a lot of audio file simultaneously

Post by problème » Sat Nov 28, 2015 4:22 pm

i will do this manually, thanks for the help

Post Reply