Exemple #1
0
def queue(position):
    """Add item at position in collection to playlist"""
    global _playlist
    collection = get_collection()
    _playlist.append(collection[position])
    log.info("Adding : %s" % collection[position])
    start_player()
Exemple #2
0
def micro_server(server_address, handle_request):
    address_family = socket.AF_INET
    socket_type = socket.SOCK_STREAM
    request_queue_size = REQUEST_QUEUE_SIZE

    # Create a new socket
    listen_socket = socket.socket(address_family, socket_type)
    # Allow to reuse the same address
    listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    # Bind
    listen_socket.bind(server_address)
    # Activate
    listen_socket.listen(request_queue_size)
    log.debug("Parent PID (PPID): {pid}\n".format(pid=os.getpid()))

    signal.signal(signal.SIGCHLD, handle_signal)

    while True:
        # New client connection
        client_connection, client_address = listen_socket.accept()
        # Handle request
        log.info("Start connected %s" % client_address[0])
        pid = os.fork()
        if pid == 0:
            listen_socket.close()  # close child copy
            handle_request(client_connection)
            client_connection.close()
            os._exit(0)
        else:
            client_connection.close()
Exemple #3
0
def _start_player():
    """Play all items found on Playlist sequentially on Radio.

    Starts player and radio process. Waits for the processes to end.
    Returns if _stop_requested or playlist is empty
    """
    global source, player, _stop_requested

    _player_lock.acquire()
    while _playlist:
        try:
            log.info("Playing : %s" % _playlist[0])
            # avconv -i "$File" -f s16le -ar 44100 -ac 2 -loglevel panic -
            source = subprocess.Popen(
                    ["avconv", "-i", "Music/%s" % _playlist[0], "-f", "s16le", "-ar", "44100", "-ac", "2", "-loglevel",
                     "panic", "-"],
                    stdout=subprocess.PIPE)

            if _radio_out:
                # ./pifm - "$2" 44100 stereo "$Volume"
                player = subprocess.Popen(["./pifm", "-", "%.1f" % _freq, "44100", "stereo", str(_volume)],
                                          stdin=source.stdout)
            else:
                # aplay -c 2 -f cd -q
                player = subprocess.Popen(["aplay", "-c", "2", "-f", "cd", "-q"],
                                          stdin=source.stdout)

            source.stdout.close()
        except Exception as error:
            log.error("Error: %s" % error.message)

        api.inform_subscribers()
        ws.inform_subscribers()

        if player:
            log.debug("player.wait() :)")
            player.wait()
            log.debug("Player terminated :)")
        if source:
            log.debug("source.wait() :)")
            source.wait()
            log.debug("Source terminated :)")

        if _stop_requested:
            _stop_requested = False
            break

        _playlist.pop(0)

    source = None
    player = None
    api.inform_subscribers()
    ws.inform_subscribers()

    _player_lock.release()
    log.info("Thread terminated :)")
 def can_close(self):
     log.info("Activity requested to stop...")
     self.chess.stop()
     return True
 def start_cb(self, param):
     log.info("Starting pygame widget...")
     self.canvas.run_pygame(self.chess.start)
 def can_close(self):
     log.info("Activity requested to stop...")
     self.chess.stop()
     return True
 def start_cb(self, param):
     log.info("Starting pygame widget...")
     self.canvas.run_pygame(self.chess.start)