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


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
