Cannot get Apple Media Service Bluetooth BLE to work With Various Bluetooth Boards or Arduino

Hello. Having a hard time with this one.

The Apple Media Service is documented here (1). It seems like an elegant and simply system to control audio over BLE with a custom hardware solution.

I have set up various boards I have, including Arduino Nano BLE and Adafruit Huzzah ESP32, using fairly straightforward scripts.

This "device" I am building then should show up on the iPhone > Settings App > Bluetooth > Other Devices. I should able to connect to the device, and have it get media information from the iPhone and be able to control it

What happens is a bit odd. First nothing shows up in Other Devices. I then use a BLE integrator app like BLE Scanner, and it shows up as Arduino (despite what I name it). I can connect to it, and interesting it lists APPLE MEDIA as a service UUID (which is correct!).

Now if I go back to Settings App > Bluetooth, because I have connected to my device with BLE Scanner, it shows as connected and under "My Devices" ! However it doesn't work, no audio is controlled. As a test I tried flicking the Play Pause characteristic but it does nothing (can see it in the Arduino code below where it flips every 4 second).

Is there an example of using Apple Media Device BLE control? I found one using MicroPython but I don't want to use micropython, and I am not sure what I am doing different.

The Arduino code is here. I have been trying to get this to work for a while now, using many, many different boards / chips. Any help is appreciated:


BLEService mediaService("89D3502B-0F36-433A-8EF4-C502AD55F8DC");

BLEUnsignedCharCharacteristic audioControlChar("9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", BLEWrite | BLENotify); 

BLEUnsignedCharCharacteristic entityUpdateChar("2F7CABCE-808D-411F-9A0C-BB92BA96C102", BLEWrite | BLENotify); 
BLEUnsignedCharCharacteristic entityAttributeChar("C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", BLEWrite | BLERead); 

int playPauseSwitch = 1;  // for now flip between 0 (pause) and play (1) on 9B3C81D8 characteristic, every 4 seconds
long previousMillis = 0;  // count for test to flip play pause

void setup() {
  Serial.begin(9600);  
  while (!Serial);

  pinMode(LED_BUILTIN, OUTPUT); 

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  BLE.setLocalName("MediaController");

  mediaService.addCharacteristic(audioControlChar); 
  mediaService.addCharacteristic(entityUpdateChar);
  mediaService.addCharacteristic(entityAttributeChar);
  
  BLE.setAdvertisedService(mediaService); // add the service UUID
  BLE.addService(mediaService); 

  BLE.advertise();

  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {
  // wait for a BLE central
  BLEDevice central = BLE.central();

  // if a central is connected to the peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's BT address:
    Serial.println(central.address());
    // turn on the LED to indicate the connection:
    digitalWrite(LED_BUILTIN, HIGH);

    while (central.connected()) {
      long currentMillis = millis();
      // For now flip play pause characteristics every 4 seconds
      if (currentMillis - previousMillis >= 4000) {
        previousMillis = currentMillis;
        flipPlayPause();
      }
    }
    // when the central disconnects, turn off the LED:
    digitalWrite(LED_BUILTIN, LOW);
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}

void flipPlayPause() {

  if (playPauseSwitch == 0) {
    playPauseSwitch = 1;
  } else {
    playPauseSwitch = 0;
  }

  audioControlChar.writeValue(playPauseSwitch);

}

(1) - Apple BLE Media Service https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleMediaService_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014716-CH2-SW1

Hey! Did you ever get this to work?

From my understanding, I think you may be going about this wrong.

This "device" I am building then should show up on the iPhone > Settings App > Bluetooth > Other Devices. I should able to connect to the device, and have it get media information from the iPhone and be able to control it

Your Arduino will not (well, should not) display on this list as it is acting as a BLE Client that is looking for your phone acting as the BLE Server. I believe BLE Scanner is showing your Arduino as having the Apple Service because it is under the impression it is an iOS device emitting the AMS service, which is not what you are after.

Hi, did you manage to figure this out? I am stuck with the same problem. @amaula is correct in suggesting that the Arduino programmed this way acts as a Client.

Hello. No I gave up. Not sure if Apple Media Services is actually supported or has just been forgotten

Cannot get Apple Media Service Bluetooth BLE to work With Various Bluetooth Boards or Arduino
 
 
Q