Lớp công cụ
VideoPlayer
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Sự Kiện
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
Mẫu mã
Trình phát video (Máy chủ)
-- Điều này nên được nằm trong một "Script" với RunContext được đặt thành "Legacy" hoặc "Server"
-- Tạo màn hình video mà video hiển thị trên đó
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
-- Tạo nơi mà tài sản video xuất phát từ
local videoSource = Instance.new("VideoPlayer")
videoSource.VideoContent = Content.fromUri("rbxassetid://5608359401")
videoSource.Looping = true
videoSource.Parent = videoScreenPart
-- Tạo nơi mà âm thanh của video phát ra
local speakerPart = Instance.new("Part")
speakerPart.Anchored = true
speakerPart.Parent = workspace
local audioEmitter = Instance.new("AudioEmitter")
audioEmitter.Parent = speakerPart
-- Tạo và kết nối dây để video hiển thị hình ảnh và phát âm thanh
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
-- Phát video
-- Lưu ý: Phát video trên server không đảm bảo nó được tải hoặc đồng bộ cho tất cả client, phát trên client là ưu tiên hơn
videoSource:Play()Trình Phát Video (Bên Khách Hàng)
-- Điều này nên nằm trong một "LocalScript" hoặc "Script" với RunContext được đặt là "Client"
-- Mã tương tự như mẫu trên cho đến phần "Phát video"
-- Phát video sau khi nó đã được tải
videoSource:GetPropertyChangedSignal("IsLoaded"):Connect(function()
if videoSource.IsLoaded then
print("Video đã được tải, bắt đầu phát trong 2 giây.")
wait(2)
videoSource:Play()
end
end)
-- Tải video để sẵn sàng khi chúng ta cần nó
videoSource:LoadAsync()
wait(5)
-- Hủy tải video để tiết kiệm tài nguyên
videoSource:Unload()Tài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
Pause
VideoPlayer:Pause():()
Lợi Nhuận
()
Play
VideoPlayer:Play():()
Lợi Nhuận
()
Unload
VideoPlayer:Unload():()
Lợi Nhuận
()
Sự Kiện
PlayFailed
Tham Số