media: remove music lag
use PlayMusic() and StopMusic() due to missing StopSound() API
This commit is contained in:
+68
-77
@@ -15175,6 +15175,8 @@ function LeaPlusLC:RunOnce()
|
|||||||
-- Create tables for list data and zone listing
|
-- Create tables for list data and zone listing
|
||||||
local ListData, playlist = {}, {}
|
local ListData, playlist = {}, {}
|
||||||
local scrollFrame, willPlay, musicHandle, ZonePage, LastPlayed, LastFolder, TempFolder, HeadingOfClickedTrack, LastMusicHandle
|
local scrollFrame, willPlay, musicHandle, ZonePage, LastPlayed, LastFolder, TempFolder, HeadingOfClickedTrack, LastMusicHandle
|
||||||
|
-- place with the other locals near willPlay, musicHandle
|
||||||
|
local PrevMusicCVar = nil -- stores user-setting for Sound_EnableMusic
|
||||||
local numButtons = 15
|
local numButtons = 15
|
||||||
local uframe = CreateFrame("FRAME")
|
local uframe = CreateFrame("FRAME")
|
||||||
|
|
||||||
@@ -15381,103 +15383,89 @@ function LeaPlusLC:RunOnce()
|
|||||||
stopBtn:Hide();
|
stopBtn:Hide();
|
||||||
stopBtn:Show()
|
stopBtn:Show()
|
||||||
LeaPlusLC:LockItem(stopBtn, true)
|
LeaPlusLC:LockItem(stopBtn, true)
|
||||||
|
-- REPLACEMENT: Stop-button handler (stopBtn:SetScript("OnClick", ...))
|
||||||
stopBtn:SetScript("OnClick", function()
|
stopBtn:SetScript("OnClick", function()
|
||||||
Sound_GameSystem_RestartSoundSystem()
|
StopMusic()
|
||||||
if musicHandle then
|
if PrevMusicCVar == "0" then
|
||||||
StopSound(musicHandle)
|
SetCVar("Sound_EnableMusic", "0")
|
||||||
musicHandle = nil
|
|
||||||
-- Hide highlight bars
|
|
||||||
LastPlayed = ""
|
|
||||||
LastFolder = ""
|
|
||||||
UpdateList()
|
|
||||||
end
|
end
|
||||||
-- Cancel sound file music timer
|
PrevMusicCVar = nil
|
||||||
|
|
||||||
|
|
||||||
|
-- clear UI state
|
||||||
|
LastPlayed, LastFolder = "", ""
|
||||||
|
UpdateList()
|
||||||
|
|
||||||
if LeaPlusLC.TrackTimer then
|
if LeaPlusLC.TrackTimer then
|
||||||
LeaPlusLC.TrackTimer:Cancel()
|
LeaPlusLC.TrackTimer:Cancel()
|
||||||
end
|
end
|
||||||
-- Lock button and unregister next track events
|
isPlayingTrack = 0
|
||||||
LeaPlusLC:LockItem(stopBtn, true)
|
LeaPlusLC:LockItem(stopBtn, true)
|
||||||
uframe:UnregisterEvent("SOUNDKIT_FINISHED")
|
|
||||||
uframe:UnregisterEvent("LOADING_SCREEN_DISABLED")
|
uframe:UnregisterEvent("LOADING_SCREEN_DISABLED")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- Store currently playing track number
|
-- Store currently playing track number
|
||||||
local tracknumber = 1
|
local tracknumber = 1
|
||||||
local isPlayingTrack = 0
|
local isPlayingTrack = 0
|
||||||
|
|
||||||
-- Function to play a track and show the static highlight bar
|
-- Function to play a track and show the static highlight bar
|
||||||
|
-- REPLACEMENT: PlayTrack() (overwrite the whole current definition)
|
||||||
local function PlayTrack()
|
local function PlayTrack()
|
||||||
-- Play tracks
|
|
||||||
-- if musicHandle then StopSound(musicHandle) end
|
-- stop anything already playing
|
||||||
if isPlayingTrack == 1 then
|
StopMusic()
|
||||||
Sound_GameSystem_RestartSoundSystem()
|
|
||||||
end
|
local file, trackTime
|
||||||
-- Sound_GameSystem_RestartSoundSystem()
|
if playlist[tracknumber] and strfind(playlist[tracknumber], "#") then
|
||||||
local file, soundID, trackTime
|
-- mp3 entry with explicit length
|
||||||
if strfind(playlist[tracknumber], "#") then
|
file, trackTime = playlist[tracknumber]:match("([^,]+)%#([^,]+)")
|
||||||
if strfind(playlist[tracknumber], ".mp3") then
|
local cleanFile = file:gsub("(|C%a%a%a%a%a%a%a%a)[^|]*(|r)", "") -- strip colour codes
|
||||||
-- Music file with track time
|
if strfind(file, "cinematics/") then
|
||||||
file, trackTime = playlist[tracknumber]:match("([^,]+)%#([^,]+)")
|
cleanFile = "interface/" .. cleanFile
|
||||||
local cleanFile = file:gsub("(|C%a%a%a%a%a%a%a%a)[^|]*(|r)", "") -- Remove color tags
|
elseif strfind(file, "cinematicvoices/") or strfind(file, "ambience/") or strfind(file, "spells/") then
|
||||||
if strfind(file, "cinematics/") then
|
cleanFile = "sound/" .. cleanFile
|
||||||
cleanFile = "interface/" .. cleanFile
|
|
||||||
elseif strfind(file, "cinematicvoices/") or strfind(file, "ambience/") or strfind(file, "spells/") then
|
|
||||||
cleanFile = "sound/" .. cleanFile
|
|
||||||
else
|
|
||||||
cleanFile = "sound/music/" .. cleanFile
|
|
||||||
end
|
|
||||||
willPlay, musicHandle = PlaySoundFile(cleanFile, "Master", false, true)
|
|
||||||
isPlayingTrack = 1
|
|
||||||
else
|
else
|
||||||
-- Sound kit without track time
|
cleanFile = "sound/music/" .. cleanFile
|
||||||
file, soundID = playlist[tracknumber]:match("([^,]+)%#([^,]+)")
|
|
||||||
willPlay, musicHandle = PlaySound(soundID, "Master", false, true)
|
|
||||||
isPlayingTrack = 1
|
|
||||||
end
|
end
|
||||||
|
PlayMusic(cleanFile)
|
||||||
|
isPlayingTrack = 1
|
||||||
end
|
end
|
||||||
-- Cancel existing music timer for a sound file
|
|
||||||
|
-- cancel any previous timer and create a new one for this track
|
||||||
if LeaPlusLC.TrackTimer then
|
if LeaPlusLC.TrackTimer then
|
||||||
LeaPlusLC.TrackTimer:Cancel()
|
LeaPlusLC.TrackTimer:Cancel()
|
||||||
end
|
end
|
||||||
if strfind(playlist[tracknumber], "#") then
|
if trackTime then
|
||||||
if strfind(playlist[tracknumber], ".mp3") then
|
LeaPlusLC.TrackTimer = LibCompat.NewTimer(trackTime + 1, function()
|
||||||
-- Track is a sound file with track time so create track timer
|
StopMusic()
|
||||||
LeaPlusLC.TrackTimer = LibCompat.NewTimer(trackTime + 1, function()
|
if tracknumber == #playlist then
|
||||||
if musicHandle then
|
tracknumber = 1
|
||||||
StopSound(musicHandle)
|
end
|
||||||
end
|
PlayTrack()
|
||||||
if tracknumber == #playlist then
|
isPlayingTrack = 1
|
||||||
-- Playlist is at the end, restart from first track
|
end)
|
||||||
tracknumber = 1
|
|
||||||
end
|
|
||||||
PlayTrack()
|
|
||||||
isPlayingTrack = 1
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
-- Store its handle for later use
|
|
||||||
LastMusicHandle = musicHandle
|
|
||||||
LastPlayed = playlist[tracknumber]
|
LastPlayed = playlist[tracknumber]
|
||||||
tracknumber = tracknumber + 1
|
tracknumber = tracknumber + 1
|
||||||
-- Show static highlight bar
|
|
||||||
|
-- static highlight
|
||||||
for index = 1, numButtons do
|
for index = 1, numButtons do
|
||||||
local button = scrollFrame.buttons[index]
|
local button = scrollFrame.buttons[index]
|
||||||
local item = button:GetText()
|
local item = button:GetText()
|
||||||
if item then
|
if item and strfind(item, "#") then
|
||||||
if strfind(item, "#") then
|
local itm = item:match("([^,]+)%#")
|
||||||
local item, void = item:match("([^,]+)%#([^,]+)")
|
if itm == file and LastFolder == TempFolder then
|
||||||
if item then
|
button.s:Show()
|
||||||
if item == file and LastFolder == TempFolder then
|
else
|
||||||
button.s:Show()
|
button.s:Hide()
|
||||||
else
|
|
||||||
button.s:Hide()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Create editbox for search
|
-- Create editbox for search
|
||||||
local sBox = LeaPlusLC:CreateEditBox("MusicSearchBox", LeaPlusLC["Page9"], 78, 10, "TOPLEFT", 150, -260, "MusicSearchBox", "MusicSearchBox")
|
local sBox = LeaPlusLC:CreateEditBox("MusicSearchBox", LeaPlusLC["Page9"], 78, 10, "TOPLEFT", 150, -260, "MusicSearchBox", "MusicSearchBox")
|
||||||
sBox:SetMaxLetters(50)
|
sBox:SetMaxLetters(50)
|
||||||
@@ -15726,14 +15714,19 @@ function LeaPlusLC:RunOnce()
|
|||||||
ShowRandomList()
|
ShowRandomList()
|
||||||
return
|
return
|
||||||
elseif strfind(item, "#") then
|
elseif strfind(item, "#") then
|
||||||
-- Enable sound if required
|
-- Enable all sound if the user had it off
|
||||||
if GetCVar("Sound_EnableAllSound") == "0" then
|
if GetCVar("Sound_EnableAllSound") == "0" then
|
||||||
SetCVar("Sound_EnableAllSound", "1")
|
SetCVar("Sound_EnableAllSound", "1")
|
||||||
end
|
end
|
||||||
-- Disable music if it's currently enabled
|
-- remember user music CVar and ensure music channel is on for PlayMusic()
|
||||||
if GetCVar("Sound_EnableMusic") == "1" then
|
if not PrevMusicCVar then
|
||||||
SetCVar("Sound_EnableMusic", "0")
|
PrevMusicCVar = GetCVar("Sound_EnableMusic")
|
||||||
end
|
end
|
||||||
|
if GetCVar("Sound_EnableMusic") == "0" then
|
||||||
|
SetCVar("Sound_EnableMusic", "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Add all tracks to playlist
|
-- Add all tracks to playlist
|
||||||
wipe(playlist)
|
wipe(playlist)
|
||||||
local StartItem = 0
|
local StartItem = 0
|
||||||
@@ -15862,16 +15855,14 @@ function LeaPlusLC:RunOnce()
|
|||||||
LeaPlusLC["Page9"]:RegisterEvent("PLAYER_LOGOUT")
|
LeaPlusLC["Page9"]:RegisterEvent("PLAYER_LOGOUT")
|
||||||
LeaPlusLC["Page9"]:RegisterEvent("UI_SCALE_CHANGED")
|
LeaPlusLC["Page9"]:RegisterEvent("UI_SCALE_CHANGED")
|
||||||
LeaPlusLC["Page9"]:SetScript("OnEvent", function(self, event)
|
LeaPlusLC["Page9"]:SetScript("OnEvent", function(self, event)
|
||||||
|
-- REPLACEMENT: PLAYER_LOGOUT part of Page9:SetScript("OnEvent", ...)
|
||||||
if event == "PLAYER_LOGOUT" then
|
if event == "PLAYER_LOGOUT" then
|
||||||
-- Stop playing at reload or logout
|
StopMusic()
|
||||||
if isPlayingTrack == 1 then
|
if PrevMusicCVar == "0" then
|
||||||
Sound_GameSystem_RestartSoundSystem()
|
SetCVar("Sound_EnableMusic", "0")
|
||||||
end
|
|
||||||
if musicHandle then
|
|
||||||
StopSound(musicHandle)
|
|
||||||
end
|
end
|
||||||
|
PrevMusicCVar = nil
|
||||||
elseif event == "UI_SCALE_CHANGED" then
|
elseif event == "UI_SCALE_CHANGED" then
|
||||||
-- Refresh list
|
|
||||||
UpdateList()
|
UpdateList()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user