Skip to content

Latest commit

 

History

History
212 lines (170 loc) · 6.75 KB

README.md

File metadata and controls

212 lines (170 loc) · 6.75 KB

Frantic's Youtube Player Library for QBCore

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.

General Information

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.

Dependencies

This library depends on:
oxmysql by Overextended

Installation

Try one of the working methods below

Older QBCore

  1. Download the Latest Release.
  2. Extract content into somewhere convenient in the resources folder.
  3. (Optional) Put ensure Frantic_Youtube into the server.cfg.
  4. Navigate to your qb-core's player.lua script. Generally, it's location is
    resources\[qb]\qb-core\server\player.lua.
  5. Find the QBCore.Player.CheckPlayerData function, located around 100th line, you can search for
    function QBCore.Player.CheckPlayerData(source, PlayerData).
  6. Find the --Metadata part.
    If you can't find it and there's metadata = { instead, try continuing with the Newer QBCore installation.
  7. 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,
}
  1. Finally, run the SQL file for your database.

Newer QBCore

  1. Download the Latest Release.
  2. Extract content into somewhere convenient in the resources folder.
  3. (Optional) Put ensure Frantic_Youtube into the server.cfg.
  4. Navigate to your qb-core's config.lua file. Generally, it's location is
    resources\[qb]\qb-core\config.lua.
  5. Find the QBConfig.Player.PlayerDefaults table, .located around 20th line.
  6. Find the metadata = { part.
  7. Then add thid code in an appropriate place, preferably right after the phonedata = {} part:
FranticYoutube = {
	ListenerVolume = 0.5,
	SpeakerVolume = 1.0,
}
  1. Finally, run the SQL file for your database.

Usage - Callbacks and Events

  1. 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.

  2. 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).
    }
  3. 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.
    }
  4. 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.
    }
  5. 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.
    }
  6. 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)

  7. 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"

  8. 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.

  9. 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.

  10. 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