MusicData = {} local volume = 0.2 StreamMode = false local function CurrentMusicId() return "music:" .. tostring(CurrentPlayerId) end RegisterNUICallback("gksphone:musicListen", function(data, cb) if data.type == "music" then TriggerServerEvent("gksphone:server:musicListen", data.musicid, volume, "play", data.time) elseif data.type == "call" or data.type == "notification" then TriggerServerEvent("gksphone:server:musicListen", data.musicid, data.volume, data.type) end cb("ok") end) RegisterNUICallback("gksphone:client:playMusic", function(data, cb) local result = "ok" local soundId = CurrentMusicId() if data.action == "volume" then volume = data.volume end if data.action == "stopcall" then TriggerServerEvent("gksphone:server:musicListen", false, false, "stopcall", false) elseif MusicData[soundId] then if data.action == "stop" then local state = exports["gks-sound"]:GetState(soundId) if state then result = { time = state.offset or 0 } end end if data.action == "volume" then TriggerServerEvent("gksphone:server:musicListen", false, data.volume, "volume", false) elseif data.action == "seek" then TriggerServerEvent("gksphone:server:musicListen", false, false, "seek", data.seekTime) else TriggerServerEvent("gksphone:server:musicListen", data.musicid or false, false, data.action, false) end elseif data.action == "musicNext" then TriggerServerEvent("gksphone:server:musicListen", data.musicid or false, volume, "musicNext", 0) end cb(result) end) local function RegisterMusicCallbacks(soundId) CreateThread(function() for _ = 1, 40 do if exports["gks-sound"]:Exists(soundId) then break end Wait(50) end if not exports["gks-sound"]:Exists(soundId) then return end MusicData[soundId] = { progressRunning = false } exports["gks-sound"]:On(soundId, "start", function() if not MusicData[soundId] or MusicData[soundId].progressRunning then return end MusicData[soundId].progressRunning = true CreateThread(function() while MusicData[soundId] do local state = exports["gks-sound"]:GetState(soundId) local duration = state and state.duration or 0 local currentTime = state and state.offset or 0 local progress = duration > 0 and (currentTime / duration) * 100 or 0 SendNUIMessage({ action = "updateProgress", progress = progress, currentTime = currentTime }) Wait(200) end end) end) exports["gks-sound"]:On(soundId, "ended", function() MusicData[soundId] = nil SendNUIMessage({ action = "updatePlay", isPlay = false, isEnd = true }) TriggerServerEvent("gksphone:server:musicDestroy", soundId) end) exports["gks-sound"]:On(soundId, "pause", function() SendNUIMessage({ action = "updatePlay", isPlay = false }) end) exports["gks-sound"]:On(soundId, "resume", function() SendNUIMessage({ action = "updatePlay", isPlay = true }) end) exports["gks-sound"]:On(soundId, "destroy", function() MusicData[soundId] = nil TriggerServerEvent("gksphone:server:musicDestroy", soundId) end) end) end RegisterNetEvent("gksphone:client:musicListen", function(soundId) soundId = tostring(soundId or CurrentMusicId()) if MusicData[soundId] then return end RegisterMusicCallbacks(soundId) end) RegisterNUICallback("gksphone:streamermode", function(data, cb) exports["gks-sound"]:setStreamerMode(data.stream) StreamMode = data.stream cb("ok") end) CreateThread(function() pcall(function() StreamMode = exports["gks-sound"]:isStreamerMode() end) end)