audio_service icon indicating copy to clipboard operation
audio_service copied to clipboard

[iOS] Not able to override `.click` method

Open 838 opened this issue 2 years ago • 3 comments

Documented behaviour

| Feature | Android | iOS | macOS | Web | | headset clicks | ✅ | ✅ | ✅ | ✅ |

Actual behaviour

The .click method does not get called on iOS.

On android when using headset buttons there will be 'I/flutter (24649): ----- LOG: click(MediaButton.media)` but on iOS no logs will be outputted.

Or if in iOS trying to override the .click method either in AudioPlayerHandler or MainSwitchHandler, it won't have any effect.

  @override
  Future<void> click([MediaButton button = MediaButton.media]) {
    debugPrint('Do something...');

    return super.click(button);
  }

Minimal reproduction project

Official example: example_multiple_handlers.dart

Reproduction steps

  1. Run example_multiple_handlers.dart on an iOS device
  2. Connect your headset
  3. Start audio playback
  4. Use play/pause button on headset

Output of flutter doctor

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.78.0)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

• No issues found!```
### Devices exhibiting the bug
iOS device with Jabra headset.

838 avatar May 12 '23 16:05 838

duplicated #1009

838 avatar May 12 '23 17:05 838

@ryanheise

Do you have any idea what could be the cause of this issue or guild me how I could debug it?

838 avatar Jun 07 '23 17:06 838

@ryanheise I'm not sure this is the right way to do, but I could get click event by:

Creating a new clickNext method

- (MPRemoteCommandHandlerStatus) clickNext: (MPRemoteCommandEvent *) event {
    //NSLog(@"togglePlayPause");
    [handlerChannel invokeMethod:@"click" arguments:@{
        @"button":@(1)
    }];
    return MPRemoteCommandHandlerStatusSuccess;
}

and call it from

        case ASkipToNext:
            if (enable) {
                [commandCenter.nextTrackCommand addTarget:self action:@selector(clickNext:)];
            } else {
                [commandCenter.nextTrackCommand removeTarget:nil];
            }
            break;

Do you have any recommendation?

838 avatar Jun 27 '23 12:06 838