Video Player
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
คุณสมบัติ
วิธีการ
GetConnectedWires(pin: string):{Wire} |
GetInputPins():{string} |
GetOutputPins():{string} |
Pause():() |
Play():() |
Unload():() |
เหตุการณ์
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
ตัวอย่างโค้ด
ผู้เล่นวิดีโอ (เซิร์ฟเวอร์)
-- สิ่งนี้ควรอยู่ใน "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.fromScale(1, 1)
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()เครื่องเล่นวิดีโอ (ฝั่งไคลเอนต์)
local videoSource = Instance.new("VideoPlayer")
videoSource.VideoContent = Content.fromUri("rbxassetid://5608359401")
videoSource.Parent = script.Parent
-- เล่นวิดีโอหลังจากที่มันโหลดเสร็จ
videoSource:GetPropertyChangedSignal("IsLoaded"):Connect(function()
if videoSource.IsLoaded then
print("วิดีโอโหลดเสร็จแล้ว กำลังเริ่มเล่นใน 2 วินาที.")
task.wait(2)
videoSource:Play()
end
end)
-- โหลดวิดีโอเพื่อให้พร้อมเมื่อเราต้องการ
videoSource:LoadAsync()
task.wait(5)
-- ยกเลิกการโหลดวิดีโอเพื่อลดการใช้ทรัพยากร
videoSource:Unload()เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
วิธีการ
Get Connected Wires
Pause
Video Player: Pause():()
ส่งค่ากลับ
()
Play
Video Player: Play():()
ส่งค่ากลับ
()
Unload
Video Player: Unload():()
ส่งค่ากลับ
()
เหตุการณ์
Play Failed
พารามิเตอร์