--######################################################################################################### -- PLAYLIST ACTIONS V1.0.0.0 By RizlaUK (www.dnet-software.com) --######################################################################################################### -- Playlist.AddFile(string Filepath);, Adds an audio file to the playlist and returns the index of the new playlist item, -1 if any error. -- Playlist.AddFolder(string Folderpath, boolean Recurse, function CallBack, function FoundCallBack);, Searches for audio files in a folder and adds them to the playlist, returns the number of tracks added to the playlist, 0 if any error -- Playlist.AddM3U(string Filepath);, Adds a m3u file to the playlist and returns the number of tracks added, -1 if any error. -- Playlist.SaveM3U(string Filepath);, Saves the playlist to m3u file, returns true is save ok, false if not. -- Playlist.Clear();, Clears the playlist, returns nothing. -- Playlist.Count();, Returns the number of items in the playlist. -- Playlist.Load(number Index, boolean PlayAutomatic, boolean Loop);, Loads a playlist item into the audio channel, returns true if the item could be loaded, false if any error. -- Playlist.Next();, Plays the next item in the playlist, returns true if the item could be loaded, false if any error. -- Playlist.Prev();, Plays the previous item in the playlist, returns true if the item could be loaded, false if any error. -- Playlist.CurrentIndex();, Returns the index of the current playlist item, else -1 if any error. -- Playlist.CurrentPath();, Returns the filepath of the current playlist item, else a blank string ("") if any error. -- Playlist.CurrentLength();, Returns the length in seconds of the current playlist item, else -1 if any error. -- Playlist.CurrentLengthString();, Returns the length in string format eg: "00:01:34" of the current playlist item, else a blank string ("") if any error. -- Playlist.CurrentSize();, Returns the size in bytes of the current playlist item, else -1 if any error. -- Playlist.CurrentSizeString();, Returns the size in string format eg: "1.32 MB" of the current playlist item, else a blank string ("") if any error. --######################################################################################################### -- add or remove extensions here tbExtensions={"*.mp3","*.ogg","*.wav"} -- select default audio channel nMainChannel=CHANNEL_USER4 --######################################################################################################### -- START PLAYLIST ACTIONS, DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING --######################################################################################################### if not Playlist then Playlist={} end if not tbPlaylist then tbPlaylist = {} end --######################################################################################################### function Playlist.Clear() tbPlaylist={} end --######################################################################################################### function Playlist.AddFolder(strFolder,bRecurse,fCallback,fFoundCallback) nCounter=0 if Folder.DoesExist(strFolder) then for index, strExtension in tbExtensions do local tbFiles = File.Find(strFolder, strExtension, bRecurse, false, fCallback, fFoundCallback); if tbFiles then for index, strPath in tbFiles do Playlist.AddFile(strPath) nCounter=nCounter+1 end end end end return nCounter end --######################################################################################################### function Playlist.AddFile(strPath) local nIndex=-1 for index, strExtension in tbExtensions do local sExt = String.SplitPath(strPath).Extension if String.Lower(sExt) == String.Replace(strExtension,"*","") then if File.DoesExist(strPath) then local nIndex = Table.Count(tbPlaylist) + 1; tbPlaylist[nIndex]=strPath return nIndex end end end return nIndex end --######################################################################################################### function Playlist.AddM3U(strPath) local nIndex=-1 local tbM3U=TextFile.ReadToTable(strPath); if tbM3U then for index, sPath in tbM3U do if sPath ~= "" then nIndex=Playlist.AddFile(sPath) end end end return nIndex end --######################################################################################################### function Playlist.SaveM3U(strPath) local bOK = false if Table.Count(tbPlaylist) > 0 then for index, sPath in tbPlaylist do --if String.Mid(sPath, String.ReverseFind(sPath, ".") + 1, -1) ~= String.Lower("m3u") then sPath=sPath..".m3u" end TextFile.WriteFromString(strPath, sPath.."\r\n", true); error = Application.GetLastError(); if (error == 0) then bOK = true end end end return bOK end --######################################################################################################### function Playlist.Load(nIndex,bAutoStart,bLoop) local Ret=false if tbPlaylist[1] then Audio.Load(nMainChannel, tbPlaylist[nIndex], bAutoStart,bLoop); if Application.GetLastError() == 0 then Ret=true end end return Ret end --######################################################################################################### function Playlist.Next() local Ret=false if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then local nCount = Table.Count(tbPlaylist); local Next = index+1 if Next > nCount then Next=1 end Audio.Load(nMainChannel, tbPlaylist[Next], true,false); Ret=true end end end return Ret end --######################################################################################################### function Playlist.Prev() local Ret=false if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then local Prev = index-1 if Prev == 0 then Prev=Table.Count(tbPlaylist) end Audio.Load(nMainChannel, tbPlaylist[Prev], true,false); Ret=true end end end return Ret end --######################################################################################################### function Playlist.Count() return Table.Count(tbPlaylist) end --######################################################################################################### function Playlist.CurrentIndex() local nIndex = -1 if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then nIndex=index break; end end end return nIndex end --######################################################################################################### function Playlist.CurrentPath() local strPath = "" if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then strPath = strPlayingFile; break; end end end return strPath end --######################################################################################################### function Playlist.CurrentSize() local nSize = -1 if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then nSize = File.GetSize(strPlayingFile); break; end end end return nSize end --######################################################################################################### function Playlist.CurrentSizeString() local strSize = "" if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then local nSize = File.GetSize(strPlayingFile); local Size = String.ToNumber(nSize) if Size >= 1073741824 then Size = Size/1024; Size = Size/1024; Size = Size/1024; Size = Math.Round(Size, 1); Size = Size.." GB"; elseif Size >= 1048576 then Size = Size/1024; Size = Size/1024; Size = Math.Round(Size, 1); Size = Size.." MB"; elseif Size >= 1024 then Size = Size/1024 Size = Math.Round(Size, 1); Size = Size.." KB"; else Size = Math.Round(Size, 1); end strSize = Size break; end end end return strSize end --######################################################################################################### function Playlist.CurrentLength() local nLen = -1 if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then nLen = Audio.GetLength(nMainChannel); break; end end end return Math.Round(nLen,0) end --######################################################################################################### function Playlist.CurrentLengthString() local strLen = "" if tbPlaylist then local strPlayingFile = Audio.GetFilename(nMainChannel); for index, strFilepath in tbPlaylist do if strFilepath == strPlayingFile then local nLen = Audio.GetLength(nMainChannel); local nSeconds = String.ToNumber(nLen) if nSeconds == 0 then strLen = "00:00:00"; else local nHours = string.format("%02.f", Math.Floor(nSeconds/3600)); local nMins = string.format("%02.f", Math.Floor(nSeconds/60 - (nHours*60))); local nSecs = string.format("%02.f", Math.Floor(nSeconds - nHours*3600 - nMins *60)); strLen = nHours..":"..nMins..":"..nSecs end break; end end end return strLen end --######################################################################################################### -- END ACTIONS FUNCTIONS --#########################################################################################################