Exemplo n.º 1
0
def setup_bt():
    # register sink and media endpoint
    sink = PipedSBCAudioSinkWithAlsaVolumeControl()
    media = BTMedia(config.get('bluez', 'device_path'))
    media.register_endpoint(sink._path, sink.get_properties())

    def startup():
        subprocess.Popen(config.get('bt_speaker', 'startup_command'),
                         shell=True).communicate()

    def connect():
        subprocess.Popen(config.get('bt_speaker', 'connect_command'),
                         shell=True).communicate()

    def disconnect():
        sink.close_transport()
        subprocess.Popen(config.get('bt_speaker', 'disconnect_command'),
                         shell=True).communicate()

    # setup bluetooth agent (that manages connections of devices)
    agent = AutoAcceptSingleAudioAgent(connect, disconnect)
    manager = BTAgentManager()
    manager.register_agent(agent._path, "NoInputNoOutput")
    manager.request_default_agent(agent._path)

    startup()
Exemplo n.º 2
0
def setup_bt():
    # setup bluetooth agent (that manages connections of devices)
    agent = AutoAcceptSingleAudioAgent()
    manager = BTAgentManager()
    manager.register_agent(agent._path, "NoInputNoOutput")
    manager.request_default_agent(agent._path)

    # register sink and media endpoint
    sink = PipedSBCAudioSinkWithAlsaVolumeControl()
    media = BTMedia(config.get('bluez', 'device_path'))
    media.register_endpoint(sink._path, sink.get_properties())
Exemplo n.º 3
0
def setup_bt():
    # register sink and media endpoint
    sink = PipedSBCAudioSinkWithAlsaVolumeControl()
    media = BTMedia(config.get('bluez', 'device_path'))
    media.register_endpoint(sink._path, sink.get_properties())

    def startup():
        command = config.get('bt_speaker', 'startup_command')
        if not command: return
        subprocess.Popen(command, shell=True).communicate()

    def connect():
        command = config.get('bt_speaker', 'connect_command')
        if not command: return
        subprocess.Popen(command, shell=True).communicate()

    def disconnect():
        sink.close_transport()
        command = config.get('bt_speaker', 'disconnect_command')
        if not command: return
        subprocess.Popen(command, shell=True).communicate()

    def track(data):
        command = config.get('bt_speaker', 'track_command')
        if not command: return
        env = dict()
        for key in data:
            if type(data[key]) == dbus.String:
                env[key.upper()] = data[key].encode("utf-8")
        # dirty hack to prevent unnecessary double execution
        if str(env) == track.last: return
        track.last = str(env)
        subprocess.Popen(command, shell=True, env=env).communicate()

    track.last = None

    # setup bluetooth agent (that manages connections of devices)
    agent = AutoAcceptSingleAudioAgent(connect, disconnect, track)
    manager = BTAgentManager()
    manager.register_agent(agent._path, "NoInputNoOutput")
    manager.request_default_agent(agent._path)

    startup()
Exemplo n.º 4
0
def setup_bt():
    # register  media endpoint
    media = BTMedia(config.get('bluez', 'device_path'))

    # start pulseaudio daemonize
    subprocess.Popen(config.get('pulseaudio', 'start_command'),
                     shell=True).communicate()

    def connect():
        subprocess.Popen(config.get('bt_speaker', 'connect_command'),
                         shell=True).communicate()

    def disconnect():
        subprocess.Popen(config.get('bt_speaker', 'disconnect_command'),
                         shell=True).communicate()

    # setup bluetooth agent (that manages connections of devices)
    agent = AutoAcceptSingleAudioAgent(connect, disconnect)
    manager = BTAgentManager()
    manager.register_agent(agent._path, "NoInputNoOutput")
    manager.request_default_agent(agent._path)

    disconnect()
Exemplo n.º 5
0
def setup_bt():
    # register sink and media endpoint
    sink = PipedSBCAudioSinkWithAlsaVolumeControl()
    media = BTMedia(config.get('bluez', 'device_path'))
    media.register_endpoint(sink._path, sink.get_properties())

    def startup():
        print("startup")
        command = config.get('bt_speaker', 'startup_command')
        if not command: return
        subprocess.Popen(command, shell=True).communicate()
        sound = config.get('default', 'hello')
        if sound:
            playrawsound(sound)

    def playrawsound(sound):
        try:
            with open(SCRIPT_PATH + "/sounds/" + sound, "rb") as audio:
                buf = audio.read(4096)
                while len(buf) > 0:
                    sink.process.stdin.write(buf)
                    buf = audio.read(4096)
        except:
            pass

    def connect(device):
        print("connect")
        command = config.get('bt_speaker', 'connect_command')
        if command:
            env = dict()
            env['device'] = device
            try:
                name = config.get(device, 'name')
            except:
                name = config.get('default', 'name')
            if name:
                env['name'] = name
            subprocess.Popen(command, shell=True, env=env).communicate()
        print("play custom message")
        try:
            sound = config.get(device, 'hello')
        except:
            sound = config.get('default', 'hello')
        if sound:
            playrawsound(sound)

    def disconnect(device):
        sink.close_transport()
        command = config.get('bt_speaker', 'disconnect_command')
        if command:
            env = dict()
            env['device'] = device
            try:
                name = config.get(device, 'name')
            except:
                name = config.get('default', 'name')
            if name:
                env['name'] = name
            subprocess.Popen(command, shell=True, env=env).communicate()
        try:
            sound = config.get(device, 'bye')
        except:
            sound = config.get('default', 'bye')
        if sound:
            playrawsound(sound)

    def track(data):
        command = config.get('bt_speaker', 'track_command')
        if not command: return
        env = dict()
        for key in data:
            if type(data[key]) == dbus.String:
                env[key.upper()] = data[key].encode("utf-8")
        # dirty hack to prevent unnecessary double execution
        if str(env) == track.last: return
        track.last = str(env)
        subprocess.Popen(command, shell=True, env=env).communicate()

    track.last = None

    # setup bluetooth agent (that manages connections of devices)
    agent = AutoAcceptSingleAudioAgent(connect, disconnect, track)
    manager = BTAgentManager()
    manager.register_agent(agent._path, "NoInputNoOutput")
    manager.request_default_agent(agent._path)

    startup()