WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Stop currently playing music (https://www.wowinterface.com/forums/showthread.php?t=57109)

LudiusMaximus 04-15-19 01:32 AM

Stop currently playing music
 
My goal is to start my own music in certain situations. E.g.:
Code:

PlaySoundFile("Sound\\Music\\ZoneMusic\\UlduarRaidInt\\UR_TitanOrchestraIntro.mp3", "Music")
But I obviously do not want the new music to play on top of the currently played game music but to temporarily replace it. Then, when my custom music piece is over I would like the standard music loop of the game to carry on.

Is it possible?

Fizzlemizz 04-15-19 11:18 AM

Munkdev I believe posted this to stop sounds playing (if it was someone else, apologies and please let me know). Should also work for PlaySoundFile():

Lua Code:
  1. local mutex = false -- need this so it doesn't recurse when PlaySound is called from within
  2. hooksecurefunc('PlaySound', function(id)
  3.     if mutex then return end -- we called this time, just return
  4.     mutex = true -- flag mutex
  5.     -- play another sound to figure out the ID.
  6.     -- can't play the same sound because it's occupied by another handle.
  7.     local played, handle = PlaySound(id+1) -- just use the ID+1 to guarantee it's different
  8.     mutex = false -- unflag mutex
  9.     if played then
  10.         StopSound(handle-1) -- stop the sound you wanted to stop in the first place
  11.         StopSound(handle) -- stop your dummy sound
  12.     end
  13. end)
  14.  
  15. --  Stop playsound from a specific function
  16. hooksecurefunc("BNToastFrame_Show", function()
  17.     local played, handle = PlaySound(SOUNDKIT.AMB_GLUESCREEN_WORGEN)
  18.     StopSound(handle-1)
  19.     StopSound(handle)
  20. end)

There's no pause/restart functions.

SDPhantom 04-15-19 08:12 PM

All that really does is flatten the UI sound channels, it doesn't do anything to music and sounds queued up in C code. I'd suggest using PlayMusic(), which does replace the in-game music, but it plays whatever you give it in a loop. You can use StopMusic() to have the game resume playing its own.


All times are GMT -6. The time now is 09:27 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI