Page 1 of 1

Two sounds at the same time

Posted: 25 Sep 2016, 05:31
by empardopo
Is it possible to have a background music and to be able hear a second sound without stopping the background music?

I use, the command

Code: Select all

 SoundPlay, backgroundMusic.mp3
but I put

Code: Select all

 SoundPlay, soundOption.wav 
I can hear this second sound but then the backgroundMusic has stopped.

Any idea, please?

Re: Two sounds at the same time

Posted: 25 Sep 2016, 06:35
by Capn Odin
Take a look at this topic Play two sound at once.

Re: Two sounds at the same time

Posted: 30 Oct 2016, 12:40
by empardopo
Thanks.

Now, using this function

Code: Select all

playAudio(aF){
   global
   fNm++
   fLoc := a_temp, cPF := fLoc "\pF_" fNm ".ahk"
      sbCmd =
      (
         #NoTrayIcon
         cSnd := "%aF%"
         soundPlay, `% cSnd, 1
      )
   fileAppend, % sbCmd, % cPF
   if fileExist(cPF)
      run % cPF
   sleep, 500 ; <- script hangs on exit if theres no delay.
      fileDelete, % a_temp "\pF_*.ahk"
   return
}
I can use a background music but now I have the problem It's impossible to me to stop the background music when I close the script.

How can I stop the music?

Thanks in advance.

Re: Two sounds at the same time

Posted: 30 Oct 2016, 12:48
by Helgef
Add a hotkey to exitapp at the bottom of sbCmd or remove the notrayicon and right click the tray icon, then click exit.

Re: Two sounds at the same time

Posted: 30 Oct 2016, 14:08
by empardopo
Helgef wrote:Add a hotkey to exitapp at the bottom of sbCmd or remove the notrayicon and right click the tray icon, then click exit.
Are you testing that function? :D

I close my script and the music keeps playing even close it.

Re: Two sounds at the same time

Posted: 30 Oct 2016, 14:24
by Helgef
Did you test?

Code: Select all

  sbCmd =
      (
         #NoTrayIcon
         cSnd := "%aF%"
         soundPlay, `% cSnd, 1
         exitapp
         esc::exitapp
      )
Start the sound, press ESC

Re: Two sounds at the same time

Posted: 31 Oct 2016, 14:17
by empardopo
Helgef wrote:Add a hotkey to exitapp at the bottom of sbCmd or remove the notrayicon and right click the tray icon, then click exit.
tra

Sorry, I had not read the remove the notraicon.... :?

Now, my problem It's that in the PC where I'm going to run the exe from my autohotkeys script is not installed autohotkey.... Then the function is not useful for me! :thumbdown:

Another idea, please?

Re: Two sounds at the same time

Posted: 31 Oct 2016, 14:29
by Helgef
Untested:
PlaySound and DllCall.

Good Luck!

Re: Two sounds at the same time

Posted: 02 Nov 2016, 03:59
by empardopo
Helgef wrote:Untested:
PlaySound and DllCall.

Good Luck!
I thought I had fixed my problem using this:

Code: Select all

FileRead, Sound1, *c %rbackgroundSound%
   PlaySound( Sound1 )

PlaySound( ByRef Sound ) {
 Return DllCall( "winmm.dll\PlaySound" ( A_IsUnicode ? "W" : "A" ), UInt,&Sound, UInt,0, UInt, ((SND_MEMORY:=0x4)|(SND_ASYNC := 0x1)) )
}
but now I have other problem... That function is only for wav files and I need/want use mp3 files...

Thanks

Re: Two sounds at the same time

Posted: 02 Nov 2016, 06:18
by hoppfrosch
For mp3 you might use bass.dll.

Toralf once released a wrapper for bass.dll: https://autohotkey.com/board/topic/5125 ... sdll-2450/

If you're interested I could pm you Toralfs wrapper from my archive ... I simply tested your needs by starting two separate scripts using the wrapper library - and both sounds could be heard - I don't know whether it can be used to play multiple sounds from a single script