ble_apple_media_simpletest.py
1 """ 2 This example solicits that apple devices that provide notifications connect to it, initiates 3 pairing, prints existing notifications and then prints any new ones as they arrive. 4 """ 5 6 import time 7 import adafruit_ble 8 from adafruit_ble.advertising.standard import SolicitServicesAdvertisement 9 from adafruit_ble_apple_media import AppleMediaService 10 11 # PyLint can't find BLERadio for some reason so special case it here. 12 radio = adafruit_ble.BLERadio() # pylint: disable=no-member 13 a = SolicitServicesAdvertisement() 14 a.solicited_services.append(AppleMediaService) 15 radio.start_advertising(a) 16 17 while not radio.connected: 18 pass 19 20 print("connected") 21 22 known_notifications = set() 23 24 i = 0 25 while radio.connected: 26 for connection in radio.connections: 27 if not connection.paired: 28 connection.pair() 29 print("paired") 30 31 ams = connection[AppleMediaService] 32 print("App:", ams.player_name) 33 print("Title:", ams.title) 34 print("Album:", ams.album) 35 print("Artist:", ams.artist) 36 if ams.playing: 37 print("Playing") 38 elif ams.paused: 39 print("Paused") 40 41 if i > 3: 42 ams.toggle_play_pause() 43 i = 0 44 print() 45 time.sleep(3) 46 i += 1 47 48 print("disconnected")