local Songs = script.Parent:WaitForChild("Songs")
repeat task.wait() until Songs
local Holder = script.Parent:WaitForChild("Holder")
local SongName = Holder:WaitForChild("SongName")
local TimeStamp = Holder:WaitForChild("TimeStamp")
local ProgressBar = Holder:WaitForChild("SongProgress"):WaitForChild("Bar")
local ChosenSong
local SongInProgress = false
-- Set song
local function startSong(Song)
for _, Song in pairs(Songs:GetChildren()) do
Song.Playing = false
end
SongName.Text = Song.Name
Song:Play()
if not Song.IsLoaded then
Song.Loaded:Wait()
end
local totalDuration = Song.TimeLength
local totalMins, totalSecs = math.floor(totalDuration / 60), totalDuration % 60
repeat
local currentTimeStamp = Song.TimePosition
local mins = math.floor(currentTimeStamp / 60)
local secs = currentTimeStamp % 60
TimeStamp.Text = string.format("%d:%02d", mins, secs) .. " / " .. string.format("%d:%02d", totalMins, totalSecs)
ProgressBar:TweenSize(UDim2.new(currentTimeStamp / totalDuration,0,1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.1)
task.wait()
until Song.TimePosition == totalDuration or Song.Name ~= ChosenSong.Name
end
-- Button Controls
local Buttons = Holder:WaitForChild("Buttons")
local PlayButton = Buttons:WaitForChild("Play")
local PauseButton = Buttons:WaitForChild("Pause")
local VolumeOnButton = Buttons:WaitForChild("VolumeOff")
local VolumeOffButton = Buttons:WaitForChild("VolumeOn")
local RewindButton = Buttons:WaitForChild("Rewind")
local ForwardButton = Buttons:WaitForChild("Forward")
local db = false
local db_time = 2
PauseButton.MouseButton1Click:Connect(function()
if db == false then
db = true
for _, Song in pairs(Songs:GetChildren()) do
Song:Pause()
end
PauseButton.Visible = false
PlayButton.Visible = true
task.wait(db_time)
db = false
end
end)
PlayButton.MouseButton1Click:Connect(function()
if db == false then
db = true
for _, Song in pairs(Songs:GetChildren()) do
Song:Resume()
end
PlayButton.Visible = false
PauseButton.Visible = true
task.wait(db_time)
db = false
end
end)
VolumeOnButton.MouseButton1Click:Connect(function()
if db == false then
db = true
for _, Song in pairs(Songs:GetChildren()) do
Song.Volume = 0
end
VolumeOnButton.Visible = false
VolumeOffButton.Visible = true
task.wait(db_time)
db = false
end
end)
VolumeOffButton.MouseButton1Click:Connect(function()
if db == false then
db = true
for _, Song in pairs(Songs:GetChildren()) do
Song.Volume = 0.25
end
VolumeOffButton.Visible = false
VolumeOnButton.Visible = true
task.wait(db_time)
db = false
end
end)
RewindButton.MouseButton1Click:Connect(function()
local SongPos = table.find(Songs:GetChildren(),ChosenSong)
if SongPos < 2 then
ChosenSong = Songs:GetChildren()[#Songs:GetChildren()] -- Gets the very last song in line
startSong(ChosenSong)
else
ChosenSong = Songs:GetChildren()[SongPos - 1]
startSong(ChosenSong)
end
end)
ForwardButton.MouseButton1Click:Connect(function()
local SongPos = table.find(Songs:GetChildren(),ChosenSong)
if SongPos > (#Songs:GetChildren() - 1) then -- if the total num of songs is 10 then it checks if the current song is positioned 1 less
ChosenSong = Songs:GetChildren()[1] -- Gets the very last song in line
startSong(ChosenSong)
else
ChosenSong = Songs:GetChildren()[SongPos + 1]
startSong(ChosenSong)
end
end)
-- Start Song
while true do
if SongInProgress == false then
SongInProgress = true
ChosenSong = Songs:GetChildren()[math.random(1,#Songs:GetChildren())]
startSong(ChosenSong)
SongInProgress = false
print("Choosing next song...")
end
task.wait(2)
end
So when ever i press rewind it picks a different song but after 2 seconds it switches to another and stays there (same with forward)