Beispiel #1
0
def handle_request(reader, writer):
    request = yield from reader.read()
    method, url, *_ = request.decode('utf-8').split(' ')

    path, parameters = parse_url(url)
    if path.startswith("/folder"):
        folder = parameters.get("folder", 1)
        mp3.play_folder(int(folder))
    elif path.startswith("/play"):
        track = parameters.get("track", 1)
        mp3.play_track(int(track))
    elif path.startswith("/next"):
        mp3.next()
    elif path.startswith("/prev"):
        mp3.previous()
    elif path.startswith("/resume"):
        mp3.resume()
    elif path.startswith("/pause"):
        mp3.pause()

    yield from writer.awrite(
        'HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n'
    )
    with open('index.html') as f:
        for line in f:
            yield from writer.awrite(line)

    yield from writer.aclose()
Beispiel #2
0
    async def run(self):
        while True:
            if self.status == self.PLAYING:
                if self.has_song_just_finished:
                    _debug("next")
                    mp3.next()
                if not self.is_card_still_there:
                    self.pause()
                    #sometimes pause gets ignored by the player, so lets pause again, can't harm.
                    yield from asyncio.sleep_ms(100)
                    self.pause()
                else:
                    if not self.button.value():
                        #button pressed
                        if time.time() - self.button_last_pressed >= 2:
                            #mind. 2 Sekunde seit letztem mal
                            mp3.next()
                            self.button_last_pressed = time.time()
            elif self.status == self.PAUSED:
                #resume folder or play new one
                #also check special cards
                uid = self.card_id
                _debug("uid", uid)
                if uid == self.SPECIAL_CARDS["end_program"]:
                    mp3.stop()
                    raise SystemExit('Stop program')
                elif uid == self.SPECIAL_CARDS["next_unassigned_folder"]:
                    self.play_folder(self.rfid_cards.next_card_index())
                elif uid:
                    folder_id = self.rfid_cards.card_index(uid)
                    _debug("folder_id", folder_id)
                    if folder_id == self.current_folder:
                        _debug("same folder", folder_id)
                        #user put same card back
                        self.resume()
                    else:  # new card
                        self.play_folder(folder_id)
                        _debug("new card", folder_id)

            yield from asyncio.sleep_ms(100)
Beispiel #3
0
def play_next():
  mp3.next()
  return "done"
Beispiel #4
0
    try:
        br10 = brght.read()
        brnow = int(
            (br1 + br2 + br3 + br4 + br5 + br6 + br7 + br8 + br9 + br10) / 10)
        print("busy:", bsy.value(), "  brightness:", brnow, "(", br10,
              ")  sensor 2:", snsMove.value())
        if (brnow >= lvlDark):  # es ist hell
            if (snsMove.value() == 0):  #no movement
                if (bsy.value() == 0):  # it is playing
                    print("pausing")
                    mp3.pause()
                #endif
            else:  #movement detected
                if (bsy.value() == 1):  # it is not playing
                    print("playing next track")
                    mp3.set_volume(playVol)
                    mp3.next()
                #endif
            #endif
        else:  #it's dark, stop music if it is playing
            if (bsy.value() == 0):  # it is playing
                print("pausing")
                mp3.pause()
            #endif
        #endif
    #endtry
    except Exception as err:
        print("Error occured :", str(err))
    #endexcept
    time.sleep(.5)