Engine Class
VideoPlayer
Summary
Properties
Events
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
Code Samples
Video Player (Server Side)
-- This should be in a "Script" with RunContext set to "Legacy" or "Server"
-- Create what the video is displayed on
local videoScreenPart = Instance.new("Part")
videoScreenPart.Anchored = true
videoScreenPart.Size = Vector3.new(12, 6, 1)
videoScreenPart.CFrame = CFrame.new(0, 5, 0)
videoScreenPart.Parent = workspace
local videoScreenUI = Instance.new("SurfaceGui")
videoScreenUI.Parent = videoScreenPart
local videoDisplay = Instance.new("VideoDisplay")
videoDisplay.Size = UDim2.new(1, 0, 1, 0)
videoDisplay.Parent = videoScreenUI
-- Create where a video asset originates from
local videoSource = Instance.new("VideoPlayer")
videoSource.VideoContent = Content.fromUri("rbxassetid://5608359401")
videoSource.Looping = true
videoSource.Parent = videoScreenPart
-- Create where the video's audio emits from
local speakerPart = Instance.new("Part")
speakerPart.Anchored = true
speakerPart.Parent = workspace
local audioEmitter = Instance.new("AudioEmitter")
audioEmitter.Parent = speakerPart
-- Create and connect wires so that the video visually renders and emits audio
local videoWire = Instance.new("Wire")
videoWire.SourceInstance = videoSource
videoWire.TargetInstance = videoDisplay
videoWire.Parent = videoSource
local audioWire = Instance.new("Wire")
audioWire.SourceInstance = videoSource
audioWire.TargetInstance = audioEmitter
audioWire.Parent = videoSource
-- Play the video
-- Note: Playing a video on the server does not guarantee it is loaded or synced for all clients, playing on the client is preferred
videoSource:Play()Video Player (Client Side)
-- This should be in either a "LocalScript" or "Script" with RunContext set to "Client"
-- Same code as above sample until the "Play the video" section
-- Play the video after it has loaded
videoSource:GetPropertyChangedSignal("IsLoaded"):Connect(function()
if videoSource.IsLoaded then
print("Video has loaded, starting playback in 2 seconds.")
wait(2)
videoSource:Play()
end
end)
-- Load the video to have it ready when we need it
videoSource:LoadAsync()
wait(5)
-- Unload the video to save resources
videoSource:Unload()API Reference
Properties
Methods
Pause
VideoPlayer:Pause():()
Returns
()
Play
VideoPlayer:Play():()
Returns
()
Unload
VideoPlayer:Unload():()
Returns
()
Events
PlayFailed
Parameters