Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local speaker = peripheral.find("speaker")
- local dfpwm = require("cc.audio.dfpwm")
- local monitor = peripheral.wrap("left")
- local songLoaded = false -- Åarkının yüklenip yüklenmediÄini kontrol etmek için bayrak
- local modemSide = "back"
- local isPlaying = false
- local volume = 1.0
- local maxBarWidth = 16 -- Maksimum çubuk geniÅliÄi
- local function drawControls()
- monitor.setBackgroundColor(colors.gray)
- monitor.clear()
- term.redirect(monitor)
- monitor.setCursorPos(6, 5)
- monitor.setTextScale(1.5)
- monitor.setTextColor(colors.white)
- if isPlaying then
- paintutils.drawLine(5, 6, 15, 6, colors.red)
- paintutils.drawLine(5, 4, 15, 4, colors.red)
- monitor.setCursorPos(5, 5)
- monitor.setBackgroundColor(colors.red)
- monitor.setTextColor(colors.white)
- monitor.write(" [Stop ||] ")
- else
- paintutils.drawLine(5, 6, 15, 6, colors.green)
- paintutils.drawLine(5, 4, 15, 4, colors.green)
- monitor.setCursorPos(5, 5)
- monitor.setBackgroundColor(colors.green)
- monitor.setTextColor(colors.white)
- monitor.write(" [Play |>] ")
- end
- paintutils.drawLine(4, 8, 16, 8, colors.blue)
- paintutils.drawLine(4, 10, 16, 10, colors.blue)
- monitor.setCursorPos(4, 9)
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- monitor.write(" [Rewind <<] ")
- paintutils.drawLine(4, 17, 15, 17, colors.orange)
- paintutils.drawLine(4, 15, 15, 15, colors.orange)
- monitor.setCursorPos(4, 16)
- monitor.setBackgroundColor(colors.orange)
- monitor.setTextColor(colors.black)
- monitor.write(" [ Upload ] ")
- -- Draw volume bar
- monitor.setCursorPos(3, 12)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- monitor.write("[Volume: " .. tostring(volume * 100) .."%]")
- monitor.setCursorPos(2, 14)
- local barWidth = math.floor(volume * maxBarWidth)
- local emptyWidth = maxBarWidth - barWidth
- for i = 1, barWidth do
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- end
- for i = 1, emptyWidth do
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ")
- end
- monitor.setCursorPos(1, 14)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- monitor.write("[ ")
- monitor.setCursorPos(17, 14)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- monitor.write(" ]")
- monitor.setCursorPos(2, 12)
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- monitor.write("<")
- monitor.setCursorPos(17, 12)
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- monitor.write(">")
- local w, h = monitor.getSize()
- monitor.setCursorPos(1, 1)
- monitor.setBackgroundColor(colors.green)
- monitor.setTextColor(colors.white)
- monitor.write(" Now playing ")
- monitor.setCursorPos(1, 2)
- monitor.write("tapeLabel")
- if lamba then
- monitor.setCursorPos(17, 17)
- monitor.setBackgroundColor(colors.green)
- monitor.setTextColor(colors.white)
- monitor.write("on ")
- else
- monitor.setCursorPos(17, 17)
- monitor.setBackgroundColor(colors.red)
- monitor.setTextColor(colors.white)
- monitor.write("off")
- end
- end
- drawControls()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- if x >= 1 and x <= 15 and y >= 15 and y <= 17 then
- term.clear()
- term.redirect(term.native())
- print("Where's the music at?")
- write("URL:")
- local url = read()
- local response = http.get(url, nil, true)
- local function stringChunks(str)
- local chunkSize = 16 * 524
- local start = 1
- return function()
- if start > #str then
- return nil
- else
- local chunk = str:sub(start, start + chunkSize - 1)
- start = start + chunkSize
- return chunk
- end
- end
- end
- if response then
- local responseData = response.readAll()
- response.close()
- local decoder = dfpwm.make_decoder()
- for chunk in stringChunks(responseData) do
- local buffer = decoder(chunk)
- speaker.playAudio(buffer)
- end
- songLoaded = true
- end
- term.redirect(monitor)
- drawControls()
- elseif x >= 1 and x <= 10 and y == 5 then
- if isPlaying then
- isPlaying = false
- speaker.stopAudio()
- else
- if songLoaded then
- isPlaying = true
- speaker.playAudio()
- end
- end
- drawControls()
- elseif x >= 1 and x <= 3 and y == 12 then
- if volume > 0.0 then
- volume = volume - 0.1
- speaker.setVolume(volume)
- end
- drawControls()
- elseif x >= 16 and x <= 17 and y == 12 then
- if volume < 1.0 then
- volume = volume + 0.1
- speaker.setVolume(volume)
- end
- drawControls()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement