This is a library for playing YouTube videos as sounds in the background in FiveM's QBCore Framework.
Because it doesn't download or stream anything, it complies with YouTube ToS. It's built completely upon YouTube's API.
It's not yet perfect, but hopefully, it will be useful for people.
This is not a standalone asset; as stated, it's a 'library' for being used by other assets.
Credit to FranticDreamer is not required, but hugely appreciated. However, keep the LICENSE.md in your source code folder and don't delete it.
Feel free to create issues and pull requests. If you fix a bug, don't keep it on your server. Share with people with a pull request, please.
Videos are networked, attached to players and listenable by everyone in a certain radius.
Radius is in the config.lua
Default settings:
Server updates clients every second.
Client updates videos every 10th of a second.
This library depends on:
oxmysql by Overextended
Try one of the working methods below
- Download the Latest Release.
- Extract content into somewhere convenient in the resources folder.
- (Optional) Put
ensure Frantic_Youtube
into the server.cfg. - Navigate to your qb-core's player.lua script. Generally, it's location is
resources\[qb]\qb-core\server\player.lua
. - Find the
QBCore.Player.CheckPlayerData
function, located around 100th line, you can search for
function QBCore.Player.CheckPlayerData(source, PlayerData)
. - Find the
--Metadata
part.
If you can't find it and there'smetadata = {
instead, try continuing with the Newer QBCore installation. - Then add thid code in an appropriate place, preferably right before the
-- Job
part:
PlayerData.metadata['FranticYoutube'] = PlayerData.metadata['FranticYoutube'] or {
ListenerVolume = 0.5,
SpeakerVolume = 1.0,
}
- Finally, run the SQL file for your database.
- Download the Latest Release.
- Extract content into somewhere convenient in the resources folder.
- (Optional) Put
ensure Frantic_Youtube
into the server.cfg. - Navigate to your qb-core's config.lua file. Generally, it's location is
resources\[qb]\qb-core\config.lua
. - Find the
QBConfig.Player.PlayerDefaults
table, .located around 20th line. - Find the
metadata = {
part. - Then add thid code in an appropriate place, preferably right after the
phonedata = {}
part:
FranticYoutube = {
ListenerVolume = 0.5,
SpeakerVolume = 1.0,
}
- Finally, run the SQL file for your database.
-
Server Callback - Add new video to a playlist:
'Frantic_Youtube:server:AddVideoToPlaylist'
Adds a new ID to a given playlist for the source client
Example arguments to Pass:
data = { url = 'dQw4w9WgXcQ', -- YouTube Video ID playlistActive = { id = 0, -- Target Playlist ID }, }
Returns: Video data of the newly added track.
-
Server Event - Set Video Playing Status:
'Frantic_Youtube:server:SetVideoPlayingStatus'
Sets the source client's video playback status.
Example arguments to Pass:
data = { state = 1, -- 1 = Play. -- 2 = Pause. -- 0 = End (Stop). }
-
Server Event - Set Video Time:
'Frantic_Youtube:server:SetVideoTime'
Sets the source client's video time to the argument.
Example arguments to Pass:
data = { time = 115, -- Time in seconds. }
-
Server Event - Set Speaker Volume:
'Frantic_Youtube:server:SetCitizenSpeakerVolume'
Sets the source client's speaker volume. This will change the source client's video volume for everyone.
Example arguments to Pass:
data = { speakerVolume = 1.0, -- Between 0.0 and 1.0. -- 0.0 = Silent. -- 1.0 = Full volume. }
-
Server Event - Set Listener Volume:
'Frantic_Youtube:server:SetCitizenListenerVolume'
Sets the source client's listener volume. This will change the source client's listening volume for every video source.
Example arguments to Pass:
data = { listenerVolume = 1.0, -- Between 0.0 and 1.0. -- 0.0 = Silent. -- 1.0 = Full volume. }
-
Server Callback - Create New Playlist:
'Frantic_Youtube:server:CreateNewPlaylist'
Creates a new playlist for the source client.
Example arguments to Pass:
data = { name = 'New Playlist', -- Name of the playlist that will be created. videos = '', -- Initial video data. I suggest leaving it empty and using AddVideoToPlaylist afterwards. }
Returns: Nothing. (TODO: Should return new playlist ID)
-
Server Callback - Play Video with ID:
'Frantic_Youtube:server:PlayVideoWithID'
Plays a video for the source client and adds it to the video history.
Example arguments to Pass:
data = { url = 'dQw4w9WgXcQ', -- YouTube ID of the video to play }
Returns: Video Data OR "timeout"
-
Server Callback - Get Citizen Videos:
'Frantic_Youtube:server:GetCitizenVideos'
Used for retrieving source client's video history.
Example arguments to Pass:
No arguments
Returns: A list of client's played videos.
-
Server Callback - Get Citizen Playlists:
'Frantic_Youtube:server:GetCitizenPlaylists'
Used for retrieving source client's playlists.
Example arguments to Pass:
No arguments
Returns: A list of client's playlists.
-
Client Event Handler - Update Video Data (For your Resource):
'Frantic_Youtube:client:UpdateVideoDataResource'
You can use this with AddEventHandler to do stuff with updated song data.
This is called every time after server updates the song data for clients.
Example arguments that will be given in order:
sourceTable = { -- Table of sources with player IDs "25_1" = { -- An example source with player ID of 25 source = 25, -- Owner Client ID index = 1, -- For now, we use only 1 videoUrl = 'dQw4w9WgXcQ', -- Youtube ID of Current Video videoStartTime = 124, -- Start Time (in Server Sync Time) videoCurrentTime = 152, -- Current Video Time videoDuration = 220, -- Current Video Total Duration videoState = 1, -- Current Video State videoVolume = 1, -- Current Video Volume videoLoaded = false, -- Is Video Finished Buffering? videoSpeakerVolume = 1, -- Speaker Volume of the Owner Client } }, vidServerTime = 100 -- Server sync time