function AudioLib.new(j)local f={}f.DefaultProperties={Children=nil;Looped=false;PlaybackSpeed=1,Playing=false;SoundId=nil;TimePosition=0,Volume=.25}f.Playlist={}f.Shuffle=false function f.GetSound(j)return j.Sound end function f.UpdateSound(f,j)for j,a in pairs(j)do f.Sound[j]=a end return f.Sound end function f.SoundEnded(j)if#j.Playlist>0 then local f=table.find(j.Playlist,j.Sound.SoundId)if j.Shuffle then f=math.random(0,#j.Playlist)end if f+1>#j.Playlist then f=0 end j.Sound.SoundId=j.Playlist[f+1]end end local a=workspace:FindFirstChild(j.Name)f.Sound=a:FindFirstChild("\065\117\100\105\111\076\105\098\095\083\111\117\110\100")if not f.Sound then f.Sound=Instance.new("\083\111\117\110\100")f.Sound.Name="\065\117\100\105\111\076\105\098\095\083\111\117\110\100"f.Sound.Parent=a f.Sound.Ended:Connect(function()f:SoundEnded()end)f:UpdateSound(f.DefaultProperties)end return f end return AudioLib
--AudioLib.__index = function(s, i) return s[i] end

function AudioLib.new(container)
	local self = {}

	self.DefaultProperties = {
		Children = nil,
		--ClearAllChildren = true;

		Looped = false,
		PlaybackSpeed = 1,
		Playing = false,
		SoundId = nil,
		TimePosition = 0,
		Volume = 0.25,
	}

	self.Playlist = {}
	self.Shuffle = false

	function self:GetSound() -- Retrieve the sound used for playing all music
		return self.Sound
	end

	function self:UpdateSound(data) -- Loops through a table of properties used to overwrite those of an existing instance.
		for property, value in pairs(data) do
			self.Sound[property] = value
		end
		return self.Sound
	end

	function self:SoundEnded() -- Loads the next song in the playlist
		if #self.Playlist > 0 then
			local index = table.find(self.Playlist, self.Sound.SoundId)
			if self.Shuffle then
				index = math.random(0, #self.Playlist)
			end
			if (index + 1) > #self.Playlist then
				index = 0
			end
			self.Sound.SoundId = self.Playlist[index + 1]
		end
	end

	local container = workspace:FindFirstChild(container.Name)
	self.Sound = container:FindFirstChild("AudioLib_Sound")
	if not self.Sound then
		self.Sound = Instance.new("Sound")
		self.Sound.Name = "AudioLib_Sound"
		self.Sound.Parent = container -- Don't ask me why I have to do this.
		self.Sound.Ended:Connect(function()
			self:SoundEnded()
		end)
		self:UpdateSound(self.DefaultProperties)
	end
	return self
end

return AudioLib
