概要
属性
活动
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
代码示例
视频播放器(服务器端)
-- 这应该在一个 "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 参考
属性
方法
Pause
VideoPlayer:Pause():()
返回
()
Play
VideoPlayer:Play():()
返回
()
Unload
VideoPlayer:Unload():()
返回
()
活动
PlayFailed