概要
屬性
活動
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
範例程式碼
影片播放器 (伺服器端)
-- 這應該在一個 "Script" 中,且 RunContext 設定為 "Legacy" 或 "Server"
-- 創建影片顯示的畫面
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
-- 創建一個影片資產的來源
local videoSource = Instance.new("VideoPlayer")
videoSource.VideoContent = Content.fromUri("rbxassetid://5608359401")
videoSource.Looping = true
videoSource.Parent = videoScreenPart
-- 創建影片的音訊發射來源
local speakerPart = Instance.new("Part")
speakerPart.Anchored = true
speakerPart.Parent = workspace
local audioEmitter = Instance.new("AudioEmitter")
audioEmitter.Parent = speakerPart
-- 創建並連接電線,使視頻可視化渲染並發出音訊
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
-- 播放視頻
-- 注意:在伺服器上播放視頻不保證它對所有客戶端都是加載或同步的,建議在客戶端播放
videoSource:Play()影片播放器(客戶端)
-- 這應該在 "LocalScript" 或 "Script" 中,且 RunContext 設為 "Client"
-- 與上面示例相同的代碼,直到 "播放視頻" 部分
-- 影片加載完成後播放
videoSource:GetPropertyChangedSignal("IsLoaded"):Connect(function()
if videoSource.IsLoaded then
print("影片已加載,2秒後開始播放。")
wait(2)
videoSource:Play()
end
end)
-- 加載影片,以便在需要時能夠準備好
videoSource:LoadAsync()
wait(5)
-- 卸載影片以節省資源
videoSource:Unload()API 參考
屬性
方法
Pause
VideoPlayer:Pause():()
返回
()
Play
VideoPlayer:Play():()
返回
()
Unload
VideoPlayer:Unload():()
返回
()
活動
PlayFailed