Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Songs = {}
- local DisplayNames = {}
- local w, h = term.getSize()
- local PlayQueue = {}
- local MusicPath = ""
- local OSVersion
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function ListFiles()
- Songs = fs.list(MusicPath)
- DisplayNames = fs.list(MusicPath)
- for i = 1, #Songs do
- Songs[i] = fs.combine(MusicPath,Songs[i])
- end
- for i = 1, #Songs do
- local Len = string.len(DisplayNames[i])
- DisplayNames[i] = string.sub(DisplayNames[i],1,Len - 6)
- end
- for i = 1, 15 do
- PlayQueue[i] = math.random(1,#DisplayNames)
- end
- end
- function CUI(m,y) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,y)
- Clear()
- for i=1, #m, 1 do --traverse the table of options
- if i==n then term.clearLine() print(i, " >",m[i]) else term.clearLine() print(i, " ", m[i]) end --print them
- end
- a, b= os.pullEvent("key") --wait for keypress
- if b==keys.w and n>1 then n=n-1 end
- if b==keys.s and n<=l then n=n+1 end
- if b==keys.enter then break end
- end
- return n --return the value
- end
- function SongPlayer(I)
- Clear()
- local dfpwm = require "cc.audio.dfpwm"
- local speaker = peripheral.find("speaker")
- local decoder = dfpwm.make_decoder()
- local BarChange = 0.2
- local BarSize = 1
- print("Now Playing "..DisplayNames[I])
- print("Length = ?")
- local event, key
- for input in io.lines(Songs[I], 16 * 1024) do
- local decoded = decoder(input)
- while not speaker.playAudio(decoded) do
- paintutils.drawFilledBox(7,6,BarSize,7,colors.red)
- BarSize = BarSize + BarChange
- os.pullEvent("speaker_audio_empty")
- end
- end
- io.close()
- MainMenu()
- end
- function MainMenu()
- term.setBackgroundColor(colors.lightGray)
- Clear()
- ListFiles()
- local options = DisplayNames
- options[#options + 1] = "Playlist"
- options[#options + 1] = "random"
- options[#options + 1] = "exit"
- local n = CUI(options,2)
- if options[n] == "exit" then
- if OSVersion == "CCSPS - Iron" then
- shell.run(settings.get("os_DesktopLoc"))
- end
- elseif options[n] == "Playlist" then
- for i = 1, #PlayQueue do
- SongPlayer(PlayQueue[i])
- end
- elseif options[n] == "random" then
- local T = math.random(1,#DisplayNames)
- SongPlayer(T)
- else
- SongPlayer(n)
- end
- end
- settings.load(".settings")
- OSVersion = settings.get("os_Version")
- if OSVersion == "CCSPS - Iron" then
- MusicPath = "os/System/Saved/Audio"
- else
- if fs.exists("os/os_SystemFiles/Audio") then
- MusicPath = "os/os_SystemFiles/Audio"
- else
- MusicPath = ""
- end
- end
- ListFiles()
- if #DisplayNames > 0 then
- MainMenu()
- else
- print("no Songs installed")
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement