Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- local dSide = "left"
- local mainColor = colors.white
- local active = false
- local repeat_ = false
- local songtimer
- local songcount = 0
- local diskList = {
- ["C418 - cat"] = 178,
- ["C418 - 13"] = 185,
- ["C418 - stal"] = 150,
- ["C418 - strad"] = 188,
- ["C418 - wait"] = 238,
- ["C418 - mall"] = 197,
- ["C418 - mellohi"] = 96,
- ["C418 - far"] = 174,
- ["C418 - ward"] = 251,
- ["C418 - blocks"] = 345,
- ["C418 - chirp"] = 185,
- ["C418 - 11"] = 77
- }
- --in case there are any changes to the original disks by mods
- diskList["C418 - wait"] = 171
- diskList["C418 - 11"] = 246
- function printMedia()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- print("Media Player 9001\n")
- if disk.hasAudio("left") then
- print(" " .. disk.getAudioTitle(dSide))
- print(" Length: " .. getTimeString(diskList[disk.getAudioTitle(dSide)]) .. "\n")
- print("Press Space to Play/Pause")
- print("Press Tab to Eject")
- print("Press LShift to Toggle Repeat")
- term.setCursorPos(1, h - 2)
- local rep = repeat_ and "On" or "Off"
- write("Repeat: " .. rep)
- term.setCursorPos(1, h - 1)
- if active then
- write("Playing...")
- term.setCursorPos(w - 3, h - 1)
- write(getTimeString(songcount))
- updateProgressBar(mainColor)
- else
- write("Stopped")
- end
- else
- print("Please insert disc")
- end
- end
- function updateProgressBar(col)
- col = col or colors.white
- term.setBackgroundColor(col)
- term.setCursorPos(1, h)
- write(string.rep(" ", songcount/diskList[disk.getAudioTitle(dSide)] * w))
- end
- function getTimeString(t)
- local sNum = t % 60 > 9 and t % 60 or "0" .. t % 60
- return math.floor(t / 60) .. ":" .. sNum
- end
- while true do
- printMedia()
- local e,k = os.pullEvent()
- if k == keys.space then
- if not active then
- songcount = 0
- songtimer = os.startTimer(1)
- disk.playAudio(dSide)
- else
- songtimer = nil
- disk.stopAudio(dSide)
- end
- active = not active
- elseif k == keys.tab then
- songtimer = nil
- active = false
- disk.stopAudio("left")
- disk.eject(dSide)
- elseif k == keys.leftShift then
- repeat_ = not repeat_
- end
- if e == "timer" and k == songtimer then
- songtimer = os.startTimer(1)
- songcount = songcount + 1
- if songcount == diskList[disk.getAudioTitle(dSide)] then
- if repeat_ then
- disk.stopAudio(dSide)
- songcount = 0
- songtimer = os.startTimer(1)
- disk.playAudio(dSide)
- else
- disk.stopAudio(dSide)
- songcount = 0
- songtimer = nil
- active = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement