Video Player
--[[
Name : Video Player
Creator : typicalusername
Description : spritesheet creator by mechaxyz, same with the sync
]]
--// Create the main instances
local owner = owner or {Character = workspace.boatliebe; Chatted = Instance.new("BindableEvent").Event}
local videoname = "Spongebob Squarepants : Band Geeks (Flag Twirlers Scene)"
local _MainPart = Instance.new("Part",owner.Character)
_MainPart.Size = Vector3.new(14.031, 9.6, 0.096)
_MainPart.Material = Enum.Material.Glass
_MainPart.Reflectance = 1
_MainPart.Anchored = true
_MainPart.Name = "_______"
local _SurfaceGui = Instance.new("SurfaceGui",_MainPart)
script.Parent = _SurfaceGui
local _Sound = Instance.new("Sound",_MainPart)
_Sound.Volume = 2.5
--_Sound.Looped = true
--_Sound.SoundId = "rbxassetid://16349365012"
local _HideFrame = Instance.new("Frame",_SurfaceGui)
_HideFrame.ZIndex = 55
_HideFrame.Size = UDim2.new(1,0,1,0)
_HideFrame.BackgroundColor3 = Color3.fromRGB(18, 54, 54)
local _Sprite = Instance.new("ImageLabel",script)
_Sprite.Size = UDim2.new(1,0,1,0)
_Sprite.Name = "Sprite"
local stupidloadinglabel = Instance.new("TextLabel",_SurfaceGui)
stupidloadinglabel.BackgroundTransparency = 1
stupidloadinglabel.AnchorPoint = Vector2.new(.5,.5)
stupidloadinglabel.Position = UDim2.new(.5,0,.5,0)
stupidloadinglabel.Text = "hold on give me a minute"
stupidloadinglabel.TextColor3 = Color3.new(1,1,1)
stupidloadinglabel.ZIndex = 56
stupidloadinglabel.TextSize = 32
_MainPart.CFrame = owner.Character.HumanoidRootPart.CFrame*CFrame.new(0,5,-5)*CFrame.Angles(0,math.rad(180),0)
--// Define the sprites and audios
local CurrentAudioSegment = 1
local AudioSegments = {
16349365012;
}
local globalwarming = {}
table.foreach(AudioSegments,function(i,v)
table.insert(globalwarming,"rbxassetid://"..tostring(v))
end)
game:GetService("ContentProvider"):PreloadAsync(globalwarming)
_Sound.SoundId = "rbxassetid://"..AudioSegments[CurrentAudioSegment]
local frames = {
[0] = {
["Rows"] = 7,
["Columns"] = 7,
["Frames"] = 46,
["Id"] = 16348147602
};
[1] = {
["Rows"] = 6,
["Columns"] = 7,
["Frames"] = 40,
["Id"] = 16348148469
};
[2] = {
["Rows"] = 2,
["Columns"] = 7,
["Frames"] = 14,
["Id"] = 16348149338
};
[3] = {
["Rows"] = 3,
["Columns"] = 7,
["Frames"] = 19,
["Id"] = 16348150210
};
[4] = {
["Rows"] = 3,
["Columns"] = 7,
["Frames"] = 16,
["Id"] = 16348150765
};
[5] = {
["Rows"] = 3,
["Columns"] = 7,
["Frames"] = 18,
["Id"] = 16348151654
};
[6] = {
["Rows"] = 6,
["Columns"] = 7,
["Frames"] = 38,
["Id"] = 16348152541
};
[7] = {
["Rows"] = 2,
["Columns"] = 7,
["Frames"] = 9,
["Id"] = 16348153070
};
[8] = {
["Rows"] = 10,
["Columns"] = 7,
["Frames"] = 70,
["Id"] = 16348154418
};
[9] = {
["Rows"] = 2,
["Columns"] = 7,
["Frames"] = 10,
["Id"] = 16348154952
};
[10] = {
["Rows"] = 1,
["Columns"] = 3,
["Frames"] = 3,
["Id"] = 16348155689
};
}
--// Preload assets
warn("This version still uses the old, slow, and unreliable httpget version for imagesizes! Beware that this will take time to load.")
function fetchSize(id)
local success,response = pcall(function()
return game:GetService("HttpService"):GetAsync(("https://rbximage.glitch.me/getimagedata/%s"):format(id:gsub("%D+","")),true);
end)
if(not success) then
error("[Failed to fetch image metadata!] Error:" .. response);
elseif(response) then
response = game:GetService("HttpService"):JSONDecode(response);
if(response.failed) then
error("[Failed to fetch image metadata, via site]");
end
end
return(response)
end
function setupSpriteSheet(frame)
local imageData = fetchSize(frame["SpriteSheet"].Image);
local mainImageSize = Vector2.new(imageData.width,imageData.height);
local vector = Vector2.new(frame.Columns,frame.Rows)
local offsetSize = mainImageSize / vector
frame["SpriteSheet"].ImageRectSize = offsetSize;
end
local ohmygodthenumber = 0
stupidloadinglabel.Text = "hold on give me a minute"
local nononononowaitwaitwait = {}
for i,v in pairs(frames) do
local Label = script.Sprite:Clone()
v["SpriteSheet"] = Label
Label.Image = "rbxassetid://"..tostring(v.Id)
table.insert(nononononowaitwaitwait,Label.Image)
Label.Visible = true
Label.Parent = script.Parent
setupSpriteSheet(v)
stupidloadinglabel.Text = "Preparing assets:\n"..i.."/"..#frames
end
stupidloadinglabel.Text = "now actually preloading.\nwill only take a sec"
game:GetService("ContentProvider"):PreloadAsync(nononononowaitwaitwait)
print("Finished processing.")
script.Parent.Frame.Visible = false
stupidloadinglabel.Text = "Now playing:\n"..videoname
stupidloadinglabel.TextSize = 24
game:GetService("TweenService"):Create(stupidloadinglabel,TweenInfo.new(5),{TextTransparency = 1; BackgroundTransparency = 1}):Play()
table.foreach(frames,function(i,v)
v.SpriteSheet.Visible = false
end)
--// Now do the thing
local goToFrame = function(image:GuiObject, frame:number, rowCount:Vector2)
local totalFrames = rowCount.X * rowCount.Y
local offsetSize = image.ImageRectSize
frame = math.clamp(frame,1,totalFrames)
local row = math.ceil((frame / totalFrames)*rowCount.Y)
local column = (frame - (rowCount.X * (row - 1)))
local xPos = (offsetSize.X * (-1 + column))
local yPos = (offsetSize.Y * (-1 + row))
image.ImageRectOffset = Vector2.new(xPos,yPos)
end
local currentFrameNum = 0
local currentFrame = frames[currentFrameNum]
--// define
local Info = {
rowCount = Vector2.new(currentFrame.Columns, currentFrame.Rows);
totalFrames = currentFrame.Frames;
atFrame = 0;
frameRate = 10;
}
currentFrame.SpriteSheet.Visible = true
goToFrame(currentFrame.SpriteSheet,0,Info.rowCount)
_MainPart.Sound:Play()
local TotalFrames = 0
local CurrentFrame1 = 0
_Sound.Ended:Connect(function()
CurrentAudioSegment = 1
CurrentFrame1 = 0
warn("_Sound has ended. Restarting...")
_Sound.SoundId = "rbxassetid://"..AudioSegments[CurrentAudioSegment]
_Sound:Play()
end)
table.foreach(frames,function(i,v)
TotalFrames+=v.Frames
end)
local duration = TotalFrames / Info.frameRate
coroutine.wrap(function()
while true do
task.wait()
local r1 = duration / TotalFrames
local r2 = r1 * CurrentFrame1
local tp = r2 * _Sound.PlaybackSpeed
if math.abs(_Sound.TimePosition - tp) >= .15 then
_Sound.TimePosition = tp
end
end
end)()
--// play
function nextSpriteSheet()
local oldframe = currentFrame
currentFrameNum = (currentFrameNum >= #frames and 0 or currentFrameNum + 1)
pcall(function()
oldframe.SpriteSheet.Visible = false; frames[currentFrameNum].SpriteSheet.Visible = true
currentFrame = frames[currentFrameNum]
Info.rowCount = Vector2.new(currentFrame.Columns, currentFrame.Rows);
Info.totalFrames = currentFrame.Frames;
end)
if currentFrameNum == 0 then
_Sound:Stop()
_MainPart.Sound.TimePosition = 0
_MainPart.Sound:Resume()
CurrentFrame1 = 0
print("Restarting video. - nextsprite")
end
warn("Spritesheet has been changed to "..currentFrameNum..".")
return 1
end
local dudeno = 0
game:GetService("RunService").PostSimulation:Connect(function()
dudeno+=1
if dudeno%(60/Info.frameRate)==0 then
Info.atFrame = (Info.atFrame + 1 > Info.totalFrames and nextSpriteSheet() or Info.atFrame + 1)
CurrentFrame1+=1
goToFrame(currentFrame.SpriteSheet,Info.atFrame,Info.rowCount)
end
end)INFO