PlaybackService
PlaybackService is a video playing module that will play videos based on these three values:
Frames
,FPS
, and ImageLabel/Button
Here are the two functions included in this module:
GenerateFrames()
| Generate a table of frames from a table of image IDs
PlayVideo()
| Play a set of frames at a custom FPS and in a custom ImageLabel using GenerateFrames()
How to use
Require the service like this:
require(module_path)
Create a new table with IDs in your script:
(E.G)
local FrameIDs = {
6060496209,
6060496895,
6060497961,
6060499848,
6060501095,
6060501718,
6060502881,
6060503657,
6060504204,
6060504916,
6060505505,
6060506233,
6060506685,
6060507074,
6060507596
}
Next, use the GenerateFrames()
function to set up your frames:
local FrameTable = PlaybackService:GenerateFrames(FrameIDs)
Finally, play the video:
local FPS = 30
local Container = script.Parent --Your ImageLabel or ImageButton
local video = PlaybackService:PlayVideo(FrameTable,FPS,Container)
MODULE:
local PlaybackService = {}
function PlaybackService:GenerateFrames(IDTable)
if typeof(IDTable) == "table" then
local frames = {}
for i,v in pairs(IDTable) do
if typeof(v) == "number" then
local id_prefix = "rbxassetid://"
local id = id_prefix..v
table.insert(frames,id)
end
end
return frames
else
warn("The value defined is not a table | PlaybackService")
return nil
end
end
function PlaybackService:PlayVideo(FrameTable,FPS,Container)
local contentprov = game:GetService("ContentProvider")
local frames = table.maxn(FrameTable)
local FPS_Time = 1/FPS
local CurrentFrame = 1
local ContentHolder = Container
contentprov:PreloadAsync({"rbxassetid://2300836745"})
ContentHolder.Image = "rbxassetid://2300836745"
contentprov:PreloadAsync(FrameTable)
if FPS > 5 then
local video = {
Frames = FrameTable,
FramesPerSecond = FPS,
Container = ContentHolder,
Finished = false
}
local images = {}
for i=1,frames do
local img = Instance.new("ImageLabel")
img.ZIndex = Container.ZIndex-i
img.Name = i
Container.Visible = false
img.Size = Container.Size
img.Position = Container.Position
img.Image = FrameTable[i]
img.Visible = true
img.Parent = Container.Parent
table.insert(images,i,img)
end
task.wait(frames*0.049019607843137254)
for i,v in pairs(images) do
wait(FPS_Time)
v.Visible = false
end
--[[repeat
ContentHolder.Image = FrameTable[CurrentFrame]
CurrentFrame = CurrentFrame+1
wait(FPS_Time)
until CurrentFrame == frames]]
--video.Finished = true
return video
end
end
return PlaybackService
EXAMPLE GUI:
VideoExample.rbxm (6.4 KB)
Video:
UPDATES
April 15th:
Added smooth playback