Thread Tools Display Modes
02-18-15, 07:54 AM   #1
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
"Sound XZ is missing" alert

Hey, I'm currently working much with my AddOn Sound Pack. It adds many new sounds to your Shared Media Library.

Now I woud like to have a chat print warning or something like this if I registered a sound file wong. Currently the file is showing up but there is no error it just won't play. Woud make it much more easy than to test all 350 files ingame.

http://wow.gamepedia.com/API_PlaySoundFile
There does not appear to be a bad error if the file is missing - it just won't play. There is a return status, which is 1 if the sound was OK and nil if it couldn't be found.

Current code:

Lua Code:
  1. local LSM = LibStub("LibSharedMedia-3.0")
  2. LSM:Register("sound", "SoundPack: Alarm_01", [[Interface\Addons\SoundPack\01_Alarms+Bells\Alarm_01.ogg]])

Lua Code:
  1. local LSM3 = LibStub("LibSharedMedia-3.0", true)
  2. local LSM2 = LibStub("LibSharedMedia-2.0", true)
  3. local SML = LibStub("SharedMedia-1.0", true)
  4.  
  5. SoundPack = {}
  6. SoundPack.revision = tonumber(string.sub("$Revision$", 12, -3)) or 1
  7.  
  8. function SoundPack:Register(mediatype, key, data, langmask)
  9.     if LSM3 then
  10.         LSM3:Register(mediatype, key, data, langmask)
  11.     end
  12.     if LSM2 then
  13.         LSM2:Register(mediatype, key, data)
  14.     end
  15.     if SML then
  16.         SML:Register(mediatype, key, data)
  17.     end
  18.     if not SoundPack.registry[mediatype] then
  19.         SoundPack.registry[mediatype] = {}
  20.     end
  21.     table.insert(SoundPack.registry[mediatype], { key, data, langmask})
  22. end
  23.  
  24. function SoundPack.OnEvent(this, event, ...)
  25.     if not LSM3 then
  26.         LSM3 = LibStub("LibSharedMedia-3.0", true)
  27.         if LSM3 then
  28.             for m,t in pairs(SoundPack.registry) do
  29.                 for _,v in ipairs(t) do
  30.                     LSM3:Register(m, v[1], v[2], v[3])
  31.                 end
  32.             end
  33.         end
  34.     end
  35.     if not LSM2 then
  36.         LSM2 = LibStub("LibSharedMedia-2.0", true)
  37.         if LSM2 then
  38.             for m,t in pairs(SoundPack.registry) do
  39.                 for _,v in ipairs(t) do
  40.                     LSM2:Register(m, v[1], v[2])
  41.                 end
  42.             end
  43.         end
  44.     end
  45.     if not SML then
  46.         SML = LibStub("SharedMedia-1.0", true)
  47.         if SML then
  48.             for m,t in pairs(SoundPack.registry) do
  49.                 for _,v in ipairs(t) do
  50.                     SML:Register(m, v[1], v[2])
  51.                 end
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. SoundPack.frame = CreateFrame("Frame")
  58. SoundPack.frame:SetScript("OnEvent", SoundPack.OnEvent)
  59. SoundPack.frame:RegisterEvent("ADDON_LOADED")
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
02-18-15, 12:02 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, as far as I know the only way to "test" a sound in-game is to play it. If you wanted to do it automatically without audibly playing the sound, I'd try setting the "Ambience" sound volume to 0, playing the sound on the "Ambienc" channel and checking the return value, then restoring the "Ambience" volume to whatever it was before. You might need to use a slightly higher value than 0, but I'd try 0 first.

However, I'm pretty sure there's also a limit on the number of sounds that can be playing at once, so you'd also need to implement some kind of queue. It's probably not worth the effort, especially since there would be interference with other addons and/or the default UI playing sounds during the test. I'd suggest partly or completely automating the process (see the MyMedia instructions in SharedMedia) so you can't screw it up by typing a file name wrong.

Also, LibSharedMedia-2.0 has been deprecated for years (it uses Ace2, which was discontinued with the launch of WotLK, so it probably doesn't even work anymore) and there never was any such thing as LibSharedMedia-1.0 (the predecessor to 2.0 was called SurfaceLib, and won't work anymore either) so you can clean up your code quite a bit by removing those. There's also no point in delaying the registration of media. Just load LibSharedMedia-3.0 (typically embedded in your addon) and then register your media directly:

Code:
## Interface: 60000
## Title: Sound Pack
## OptionalDeps: LibSharedMedia-3.0

Libs\LibStub\LibStub.lua
Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua
Libs\LibSharedMedia-3.0\LibSharedMedia-3.0.lua

SoundPack.lua
Code:
local ADDON = ...
local PATH = "Interface\\AddOns\\"..ADDON.."\\SoundFiles\\"
local M = LibStub("LibSharedMedia-3.0")

M:Register(TYPE, "A Sound",       PATH.."filename_a.ogg")
M:Register(TYPE, "Another Sound", PATH.."filename_b.ogg")
M:Register(TYPE, "Weird Sound",   PATH.."weird.ogg")
-- more sounds here
That's all you need.

Edit:
Actually it looks like you're already doing this, based on the first code you posted. I don't know what that second block is for, and it should be throwing an error anyway; you can just get rid of it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-18-15, 12:14 PM   #3
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
I see thank you! Do I realy need CallbackHandler-1.0.lua and LibSharedMedia-3.0.lua inside my libs folder? Because currently its working without
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
02-18-15, 12:20 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Tonyleila View Post
I see thank you! Do I realy need CallbackHandler-1.0.lua and LibSharedMedia-3.0.lua inside my libs folder? Because currently its working without
If you want your addon to work no matter what other addons someone is using, yes, and LibStub too. Otherwise you're depending on some other addon to load them first, but without setting a hard dependency on some specific addon (bad because your addon doesn't actually depend on another addon) or writing more code to delay everything until some other addon loads the libraries, you can't guarantee that things will happen in the right order. While you can delay for some other addon, it's better practice just to have your addon include all the things it needs.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-18-15, 06:38 PM   #5
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
You could use StopSound with the sound handle returned by PlaySoundFile to stop the file immediately after playing it during the testing phase.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » "Sound XZ is missing" alert

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