forked from Red-Killer/lb-musicapp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
139 lines (121 loc) · 4.12 KB
/
client.lua
File metadata and controls
139 lines (121 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
QBCore = exports['qb-core']:GetCoreObject()
local identifier = "youtube_music2"
CreateThread(function ()
while GetResourceState("lb-phone") ~= "started" do
Wait(500)
end
local function AddApp()
local added, errorMessage = exports["lb-phone"]:AddCustomApp({
identifier = identifier,
name = "CB Music",
description = "All your favorite music, on the go!",
developer = "Cool Brad Scripts",
defaultApp = false, -- OPTIONAL if set to true, app should be added without having to download it,
size = 59812, -- OPTIONAL in kb
--price = 999999, -- OPTIONAL, Make players pay with in-game money to download the app
images = {}, -- OPTIONAL array of images for the app on the app store
ui = GetCurrentResourceName() .. "/ui/index.html", -- this is the path to the HTML file, can also be a URL
icon = "https://cfx-nui-" .. GetCurrentResourceName() .. "/ui/assets/icon.png"
})
if not added then
print("Could not add app:", errorMessage)
end
end
AddApp()
AddEventHandler("onResourceStart", function(resource)
if resource == "lb-phone" then
AddApp()
end
end)
end)
xSound = exports.xsound
local playing = false
local volume = 50.0
local youtubeUrl = nil
local musicId = "phone_youtubemusic_id_" .. GetPlayerServerId(PlayerId())
RegisterNUICallback("playSound", function(data, cb)
local plrPed = PlayerPedId()
local plrCoords = GetEntityCoords(plrPed)
local url = data.url
TriggerServerEvent("phone:youtube_music:soundStatus", "play", { position = plrCoords, link = url })
playing = true
youtubeUrl = url
end)
RegisterNUICallback("getData", function(data, cb)
local data = {
isPlay = playing,
volume = volume,
youtubeUrl = youtubeUrl
}
cb(data)
end)
RegisterNUICallback("changeVolume", function(data, cb)
TriggerServerEvent("phone:youtube_music:soundStatus", "volume", { volume = data.volume })
volume = data.volume
end)
RegisterNUICallback("stopSound", function(data, cb)
TriggerServerEvent("phone:youtube_music:soundStatus", "stop", { })
playing = false
end)
RegisterNUICallback("saveSong", function(data, cb)
TriggerServerEvent("saveSong", data)
end)
Citizen.CreateThread(function()
Citizen.Wait(1000)
local pos
while true do
Citizen.Wait(100)
if xSound:soundExists(musicId) and playing then
if xSound:isPlaying(musicId) then
pos = GetEntityCoords(PlayerPedId())
TriggerServerEvent("phone:youtube_music:soundStatus", "position", { position = pos })
else
Citizen.Wait(1000)
end
else
Citizen.Wait(1000)
end
end
end)
RegisterNetEvent("phone:youtube_music:soundStatus", function(type, musicId, data)
if type == "position" then
if xSound:soundExists(musicId) then
xSound:Position(musicId, data.position)
end
elseif type == "play" then
xSound:PlayUrlPos(musicId, data.link, 1, data.position)
xSound:destroyOnFinish(musicId, true)
xSound:setSoundDynamic(musicId, true)
xSound:Distance(musicId, 20)
elseif type == "volume" then
if xSound:soundExists(musicId) then
data.volume = data.volume / 100
xSound:setVolumeMax(musicId, data.volume)
end
elseif type == "stop" then
if xSound:soundExists(musicId) then
xSound:Destroy(musicId)
end
end
end)
function GetSavedTracks(citizenid, cb)
QBCore.Functions.TriggerCallback('getSavedTracks', function(results)
if results then
cb(results)
else
cb({})
end
end, citizenid)
end
RegisterNUICallback("getSavedTracks", function(data, cb)
PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData then
local citizenid = PlayerData.citizenid
GetSavedTracks(citizenid, cb)
else
cb({})
end
end)
RegisterNUICallback("deleteSong", function(data, cb)
TriggerServerEvent('deleteSong', data)
end)