學習
引擎類別
VideoPlayer
無法瀏覽

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


範例程式碼
影片播放器 (伺服器端)
-- 這應該在一個 "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 參考
屬性
AutoLoadInStudio
未複製
無法建立指令碼
Roblox 指令碼安全性
平行讀取
功能: Audio, UI
VideoPlayer.AutoLoadInStudio:boolean

AutoPlayInStudio
未複製
無法建立指令碼
Roblox 指令碼安全性
平行讀取
功能: Audio, UI
VideoPlayer.AutoPlayInStudio:boolean

IsLoaded
唯讀
未複製
平行讀取
功能: Audio, UI
VideoPlayer.IsLoaded:boolean

IsPlaying
唯讀
未複製
平行讀取
功能: Audio, UI
VideoPlayer.IsPlaying:boolean

Looping
平行讀取
功能: Audio, UI
VideoPlayer.Looping:boolean

MaximumResolution
隱藏
平行讀取
功能: Audio, UI, InternalTest
VideoPlayer.MaximumResolution:Enum.VideoSampleSize

PlaybackSpeed
平行讀取
功能: Audio, UI
VideoPlayer.PlaybackSpeed:number

Resolution
唯讀
未複製
平行讀取
功能: Audio, UI
VideoPlayer.Resolution:Vector2

TimeLength
唯讀
未複製
平行讀取
功能: Audio, UI
VideoPlayer.TimeLength:number

TimePosition
平行讀取
功能: Audio, UI
VideoPlayer.TimePosition:number

VideoContent
平行讀取
功能: Audio, UI
VideoPlayer.VideoContent:Content

Volume
平行讀取
功能: Audio, UI
VideoPlayer.Volume:number

方法
GetConnectedWires
功能: Audio, UI
VideoPlayer:GetConnectedWires(pin:string):{Wire}
參數
pin:string
返回

GetInputPins
功能: Audio, UI
VideoPlayer:GetInputPins():{any}
返回

GetOutputPins
功能: Audio, UI
VideoPlayer:GetOutputPins():{any}
返回

LoadAsync
暫停
功能: Audio, UI
VideoPlayer:LoadAsync():Enum.AssetFetchStatus

Pause
功能: Audio, UI
VideoPlayer:Pause():()
返回
()

Play
功能: Audio, UI
VideoPlayer:Play():()
返回
()

Unload
功能: Audio, UI
VideoPlayer:Unload():()
返回
()

活動
DidEnd
功能: Audio, UI
VideoPlayer.DidEnd():RBXScriptSignal

DidLoop
功能: Audio, UI
VideoPlayer.DidLoop():RBXScriptSignal

PlayFailed
功能: Audio, UI
VideoPlayer.PlayFailed(error:Enum.AssetFetchStatus):RBXScriptSignal

WiringChanged
功能: Audio, UI
VideoPlayer.WiringChanged(
connected:boolean, pin:string, wire:Wire, instance:Instance
參數
connected:boolean
pin:string
wire:Wire
instance:Instance

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。