Two sounds at the same time

Get help with using AutoHotkey and its commands and hotkeys
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Two sounds at the same time

25 Sep 2016, 05:31

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?
Everything is possible!
User avatar
Capn Odin
Posts: 1291
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Two sounds at the same time

25 Sep 2016, 06:35

Take a look at this topic Play two sound at once.
Please excuse my spelling I am dyslexic.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Two sounds at the same time

30 Oct 2016, 12:40

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.
Everything is possible!
Helgef
Posts: 3776
Joined: 17 Jul 2016, 01:02
Contact:

Re: Two sounds at the same time

30 Oct 2016, 12:48

Add a hotkey to exitapp at the bottom of sbCmd or remove the notrayicon and right click the tray icon, then click exit.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Two sounds at the same time

30 Oct 2016, 14:08

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.
Everything is possible!
Helgef
Posts: 3776
Joined: 17 Jul 2016, 01:02
Contact:

Re: Two sounds at the same time

30 Oct 2016, 14:24

Did you test?

Code: Select all

  sbCmd =
      (
         #NoTrayIcon
         cSnd := "%aF%"
         soundPlay, `% cSnd, 1
         exitapp
         esc::exitapp
      )
Start the sound, press ESC
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Two sounds at the same time

31 Oct 2016, 14:17

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?
Everything is possible!
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Two sounds at the same time

02 Nov 2016, 03:59

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
Everything is possible!
User avatar
hoppfrosch
Posts: 347
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Two sounds at the same time

02 Nov 2016, 06:18

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

Return to “Ask For Help”

Who is online

Users browsing this forum: andrewvanmarle, bschamel, swagfag and 158 guests