/ README.rst
README.rst
  1  Introduction
  2  ============
  3  
  4  .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ble_apple_media/badge/?version=latest
  5      :target: https://circuitpython.readthedocs.io/projects/ble_apple_media/en/latest/
  6      :alt: Documentation Status
  7  
  8  .. image:: https://img.shields.io/discord/327254708534116352.svg
  9      :target: https://adafru.it/discord
 10      :alt: Discord
 11  
 12  .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Media/workflows/Build%20CI/badge.svg
 13      :target: https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Media/actions
 14      :alt: Build Status
 15  
 16  Support for the Apple Media Service which provides media playback info and control.
 17  
 18  
 19  Dependencies
 20  =============
 21  This driver depends on:
 22  
 23  * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
 24  
 25  Please ensure all dependencies are available on the CircuitPython filesystem.
 26  This is easily achieved by downloading
 27  `the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_.
 28  
 29  Installing from PyPI
 30  =====================
 31  
 32  On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
 33  PyPI <https://pypi.org/project/adafruit-circuitpython-ble_apple_media/>`_. To install for current user:
 34  
 35  .. code-block:: shell
 36  
 37      pip3 install adafruit-circuitpython-ble-apple-media
 38  
 39  To install system-wide (this may be required in some cases):
 40  
 41  .. code-block:: shell
 42  
 43      sudo pip3 install adafruit-circuitpython-ble-apple-media
 44  
 45  To install in a virtual environment in your current project:
 46  
 47  .. code-block:: shell
 48  
 49      mkdir project-name && cd project-name
 50      python3 -m venv .env
 51      source .env/bin/activate
 52      pip3 install adafruit-circuitpython-ble-apple-media
 53  
 54  Usage Example
 55  =============
 56  
 57  .. code-block:: python
 58  
 59      import adafruit_ble
 60      from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
 61      from adafruit_ble_apple_media import AppleMediaService
 62  
 63      radio = adafruit_ble.BLERadio()
 64      a = SolicitServicesAdvertisement()
 65      a.solicited_services.append(AppleMediaService)
 66      radio.start_advertising(a)
 67  
 68      while not radio.connected:
 69          pass
 70  
 71      print("connected")
 72  
 73      known_notifications = set()
 74  
 75      i = 0
 76      while radio.connected:
 77          for connection in radio.connections:
 78              if not connection.paired:
 79                  connection.pair()
 80                  print("paired")
 81  
 82              ams = connection[AppleMediaService]
 83              print("App:", ams.player_name)
 84              print("Title:", ams.title)
 85              print("Album:", ams.album)
 86              print("Artist:", ams.artist)
 87              if ams.playing:
 88                  print("Playing")
 89              elif ams.paused:
 90                  print("Paused")
 91  
 92              if i > 3:
 93                  ams.toggle_play_pause()
 94                  i = 0
 95          print()
 96          time.sleep(3)
 97          i += 1
 98  
 99      print("disconnected")
100  
101  
102  Contributing
103  ============
104  
105  Contributions are welcome! Please read our `Code of Conduct
106  <https://github.com/adafruit/Adafruit_CircuitPython_BLE_Apple_Media/blob/master/CODE_OF_CONDUCT.md>`_
107  before contributing to help this project stay welcoming.
108  
109  Documentation
110  =============
111  
112  For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.