eichblatt / deadstream

A time machine to play GD tapes from archive.org
GNU General Public License v3.0
51 stars 14 forks source link

bluetooth/Airplay/casting #202

Closed eichblatt closed 2 years ago

eichblatt commented 2 years ago

Damn this is hard. I've made a lot of progress, and am able to connect, but it fails with this message when i try to pair the headphones to the Raspberry Pi:


sudo bluetoothctl

: deadhead@deadstream2:~ ; sudo bluetoothctl
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:1E:F1:05 Discovering: yes
[NEW] Device 6D:7B:E8:DB:A2:A2 6D-7B-E8-DB-A2-A2
[NEW] Device 56:EE:FC:1A:76:E0 LE-Bose SoundSport
[NEW] Device 47:2C:91:9B:CB:67 47-2C-91-9B-CB-67
[NEW] Device 52:EE:E7:85:6B:71 52-EE-E7-85-6B-71
[bluetooth]# scan off
Discovery stopped
[CHG] Controller B8:27:EB:1E:F1:05 Discovering: no
[CHG] Device 52:EE:E7:85:6B:71 TxPower is nil
[CHG] Device 52:EE:E7:85:6B:71 RSSI is nil
[CHG] Device 47:2C:91:9B:CB:67 TxPower is nil
[CHG] Device 47:2C:91:9B:CB:67 RSSI is nil
[CHG] Device 56:EE:FC:1A:76:E0 TxPower is nil
[CHG] Device 56:EE:FC:1A:76:E0 RSSI is nil
[CHG] Device 6D:7B:E8:DB:A2:A2 TxPower is nil
[CHG] Device 6D:7B:E8:DB:A2:A2 RSSI is nil
[bluetooth]# connect 56:EE:FC:1A:76:E0
Attempting to connect to 56:EE:FC:1A:76:E0
[CHG] Device 56:EE:FC:1A:76:E0 Connected: yes
Connection successful
[NEW] Primary Service
        /org/bluez/hci0/dev_56_EE_FC_1A_76_E0/service0001
        0000febe-0000-1000-8000-00805f9b34fb
        Bose Corporation
[NEW] Characteristic
[NEW] Characteristic
        /org/bluez/hci0/dev_56_EE_FC_1A_76_E0/service0027/char0028
        9d410018-35d6-f4dd-ba60-e7bd8dc491c0
        Vendor specific
[NEW] Characteristic
        /org/bluez/hci0/dev_56_EE_FC_1A_76_E0/service0027/char002a
        9d410019-35d6-f4dd-ba60-e7bd8dc491c0
        Vendor specific
[NEW] Descriptor
        /org/bluez/hci0/dev_56_EE_FC_1A_76_E0/service0027/char002a/desc002c
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[CHG] Device 56:EE:FC:1A:76:E0 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 56:EE:FC:1A:76:E0 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 56:EE:FC:1A:76:E0 UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device 56:EE:FC:1A:76:E0 UUIDs: 0000febe-0000-1000-8000-00805f9b34fb
[CHG] Device 56:EE:FC:1A:76:E0 UUIDs: 0000feed-0000-1000-8000-00805f9b34fb
[CHG] Device 56:EE:FC:1A:76:E0 ServicesResolved: yes
[CHG] Device 56:EE:FC:1A:76:E0 Modalias: bluetooth:v009Ep4012d0304
[LE-Bose SoundSport]# info
Device 56:EE:FC:1A:76:E0 (random)
        Name: LE-Bose SoundSport
        Alias: LE-Bose SoundSport
        Paired: no
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        UUID: Bose Corporation          (0000febe-0000-1000-8000-00805f9b34fb)
        UUID: Tile, Inc.                (0000feed-0000-1000-8000-00805f9b34fb)
        Modalias: bluetooth:v009Ep4012d0304
        ManufacturerData Key: 0x0201
        ManufacturerData Value:
  43 92 51 d7 67 63 16                             C.Q.gc.      
[LE-Bose SoundSport]# trust 56:EE:FC:1A:76:E0
[CHG] Device 56:EE:FC:1A:76:E0 Trusted: yes
Changing 56:EE:FC:1A:76:E0 trust succeeded
[LE-Bose SoundSport]# info
Device 56:EE:FC:1A:76:E0 (random)
        Name: LE-Bose SoundSport
        Alias: LE-Bose SoundSport
        Paired: no
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        UUID: Bose Corporation          (0000febe-0000-1000-8000-00805f9b34fb)
        UUID: Tile, Inc.                (0000feed-0000-1000-8000-00805f9b34fb)
        Modalias: bluetooth:v009Ep4012d0304
        ManufacturerData Key: 0x0201
        ManufacturerData Value:
  43 92 51 d7 67 63 16                             C.Q.gc.         
[LE-Bose SoundSport]# pair 56:EE:FC:1A:76:E0
Attempting to pair with 56:EE:FC:1A:76:E0
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device 56:EE:FC:1A:76:E0 ServicesResolved: no
[CHG] Device 56:EE:FC:1A:76:E0 Connected: no
[DEL] Descriptor
        /org/bluez/hci0/dev_56_EE_FC_1A_76_E0/service0001/char0002/desc0004
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
eichblatt commented 2 years ago

I have learned a lot about bluetooth lately.

At least one of the reasons why it isn't working is that I cannot use "pulse" as my audio-device.

The reason I can't use pulse as the audio-device is that my program is launched by a systemd service, which is really run by root as a system-wide process. Pulse audio is only run as a per-user daemon. So, when I launch the service, it's not connecting to my user's pulseaudio daemon.

Note: If i wanted to set the audio device as pulse, this would be in the GDPlayer object __init__ function;

class GDPlayer(MPV):
    """ A media player to play a GDTape """

    def __init__(self, tape=None):
        super().__init__()
        # self._set_property('prefetch-playlist','yes')
        # self._set_property('cache-dir','/home/steve/cache')
        # self._set_property('cache-on-disk','yes')
        self._set_property('audio-buffer', 10.0)  # This allows to play directly from the html without a gap!
        self._set_property('cache', 'yes')
        # self.default_audio_device = 'pulse'
        self.default_audio_device = 'auto'
        audio_device = self.default_audio_device
        self._set_property('audio-device', audio_device)
        self.download_when_possible = False
        self.tape = None
        if tape is not None:
            self.insert_tape(tape)

I remember struggling to figure this out back when I was moving to using a systemd service. Ugh!

Anyway, if I could use pulse, things would be a lot easier.

eichblatt commented 2 years ago

This is now working