Video Player
*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
Phương Pháp
GetConnectedWires(pin: string):{Wire} |
GetInputPins():{string} |
GetOutputPins():{string} |
Pause():() |
Play():() |
Unload():() |
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 nằm trong một "Script" với RunContext được đặt thành "Legacy" hoặc "Server"
-- Tạo những gì 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.fromScale(1, 1)
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ị 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 rằng nó được tải hoặc đồng bộ cho tất cả các client, phát trên client là ưu tiên
videoSource:Play()Trình Phát Video (Bên Khách Hàng)
local videoSource = Instance.new("VideoPlayer")
videoSource.VideoContent = Content.fromUri("rbxassetid://5608359401")
videoSource.Parent = script.Parent
-- 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 sau 2 giây.")
task.wait(2)
videoSource:Play()
end
end)
-- Tải video để sẵn sàng khi chúng ta cần
videoSource:LoadAsync()
task.wait(5)
-- Giải phóng 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
Video Player: Pause():()
Lợi Nhuận
()
Play
Video Player: Play():()
Lợi Nhuận
()
Unload
Video Player: Unload():()
Lợi Nhuận
()
Sự Kiện
Play Failed
Tham Số