学习
引擎类
VideoPlayer
不可浏览

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


代码示例
视频播放器(服务器端)
-- 这应该在一个 "Script" 中,运行上下文设置为 "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 是我们在美国及其他国家或地区的注册与未注册商标。