Thread Tools Display Modes
04-15-19, 01:32 AM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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?
  Reply With Quote
04-15-19, 11:18 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-15-19, 08:12 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stop currently playing music

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off