Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- http://dl.dropboxusercontent.com/s/2lfujs9n53sijnx/play
- -- http://pastebin.com/xXdBcZRW
- local function update()
- local i=http.get('http://dl.dropboxusercontent.com/s/2lfujs9n53sijnx/play')
- local o=io.open(shell.getRunningProgram(),'w')
- o:write(i.readAll())
- o:write('\n')
- o:close()
- end
- local args={...}
- if args[1]=='update' then
- update()
- return
- end
- local drive=peripheral.wrap('front')
- local songs={
- ['C418 - 13']=178,
- ['C418 - cat']=185,
- ['C418 - blocks']=345,
- ['C418 - chirp']=185,
- ['C418 - far']=174,
- ['C418 - mall']=197,
- ['C418 - mellohi']=96,
- ['C418 - stal']=150,
- ['C418 - strad']=188,
- ['C418 - ward']=254,
- ['C418 - 11']=71,
- ['C418 - wait']=238,
- ['Valve - Still Alive']=176,
- ['Valve - Radio Loop']=21,
- ['Valve - Want You Gone']=141,
- ['artist - song']=0,
- }
- local player
- player = {
- playing = true,
- slot = 1,
- play = function()
- player.playing = true
- if turtle.getItemCount(player.slot)>0 then
- if drive.hasAudio() then turtle.suck() end
- turtle.select(player.slot)
- turtle.drop()
- end
- drive.playAudio()
- end,
- pause = function()
- if player.playing then drive.stopAudio() else drive.playAudio() end
- player.playing = not player.playing
- end,
- stop = function()
- turtle.suck()
- player.playing = false
- end,
- skip = function(step)
- player.stop()
- step = step or 1
- repeat
- player.slot = player.slot + step
- if player.slot > 16 then player.slot = player.slot - 16 end
- if player.slot < 1 then player.slot = player.slot + 16 end
- until turtle.getItemCount(player.slot) > 0
- player.play()
- end,
- display = function()
- if player.playing then
- local title=drive.getAudioTitle()
- local length=songs[title] or 60
- print(textutils.formatTime(length/60, true)..' '..title)
- local w,h = term.getSize()
- local x,y = term.getCursorPos()
- local lengthFormatted=textutils.formatTime(length/60, true)
- local barLength = w-x-3-#lengthFormatted
- for time=0,length do
- local barFilled = math.floor(barLength*time/length)
- local timeFormatted=textutils.formatTime(time/60, true)
- term.setCursorPos(x,y)
- write(timeFormatted)
- write(' [')
- write(string.rep('#',barFilled))
- write(string.rep('-',barLength-barFilled))
- write(']')
- sleep(1)
- end
- print('')
- else
- while true do sleep(60) end
- end
- end,
- controller = function()
- while true do
- local event, scancode = os.pullEvent('key')
- --print(scancode)
- if scancode==57 then -- space
- player.pause()
- return
- elseif scancode==203 then -- left
- player.skip(-1)
- return
- elseif scancode==205 then -- right
- player.skip(1)
- return
- elseif scancode==200 then -- up
- player.skip(-4)
- return
- elseif scancode==208 then -- down
- player.skip(4)
- return
- elseif scancode==16 then -- 'q'
- player.stop()
- player.exit = true
- return
- end
- end
- end,
- run = function()
- player.play()
- repeat
- done = parallel.waitForAny( player.display, player.controller )
- if done == 1 then player.skip() end
- until player.exit
- end,
- }
- player.run()
- print('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement