ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
806 stars 481 forks source link

there has play/pause control in notification not match the empty controls setting or not set controls #1099

Open rd-wang opened 3 days ago

rd-wang commented 3 days ago

Documented behaviour

PlaybackState _transformEvent(PlaybackEvent event) {
    return PlaybackState(
      controls: [
        if (_player.playing)
          MediaControl.pause.copyWith(androidIcon: "drawable/baseline_forward_30_24")
        else
          MediaControl.play.copyWith(androidIcon: "drawable/baseline_forward_30_24"),
        MediaControl.stop.copyWith(androidIcon: "drawable/audio_service_pause"),
        MediaControl.rewind.copyWith(androidIcon: "drawable/audio_service_mute"),
        const MediaControl(
          androidIcon: 'drawable/baseline_forward_30_24',
          label: 'Fast Forward',
          action: MediaAction.fastForward,
        ),
        MediaControl.custom(
            androidIcon: 'drawable/ic_baseline_favorite_24',
            label: 'favorite',
            name: 'favorite',
            extras: <String, dynamic>{'level': 1}),
      ],
      systemActions: const {
        MediaAction.seek,
        MediaAction.stop,
        MediaAction.rewind,
        MediaAction.playPause,
        MediaAction.play,
        MediaAction.pause,
        MediaAction.seekForward,
        MediaAction.seekBackward,
      },

Actual behaviour

Question: How to replace the default play/pause icon in notification Phenomenon: Modify the button control in the notification in the controls parameter of PlaybackState, clear the list, and there will be a default play/pause icon switching function on the UI;

Add MediaControl.play with the same name but replace the iconMediaControl.play.copyWith(androidIcon: "drawable/baseline_forward_30_24") that displays the default icon;

Adding a picture with the same name as the default icon to the drawable cannot replace the default play and pause icons. But stop can be replaced. The image is not modified: MediaControl.pause.copyWith(androidIcon: "drawable/audio_service_stop"), Image modification:MediaControl.stop, Image modification:MediaControl.rewind.copyWith(androidIcon: "drawable/audio_service_stop"),

Add a custom type of controls, and the icon can take effect normally.

In the example you provided, you can reproduce this problem by directly modifying the content in controls. No other modifications are required.

Minimal reproduction project

Official example: example_android13.dart

Reproduction steps

Modify the control parameter content in the _transformEvent method and add the corresponding test image to the drawable.

Output of flutter doctor

It has nothing to do with flutter

Devices exhibiting the bug

android 14 ,Huawei Honor pro9

rd-wang commented 3 days ago

https://developer.android.com/about/versions/13/behavior-changes-13?hl=zh-cn#playback-controls Because slot 1 of android controls cannot be customized, the function of slot 1 cannot be modified?

ryanheise commented 3 days ago

Can you submit a bug report in English following the instructions?

rd-wang commented 3 days ago

Can you submit a bug report in English following the instructions?

sorry, I have modified the description。 maybe is not issue,but i have no idea for that。

ryanheise commented 3 days ago

If you want to ask a question about how set the icons on Android, please follow the instructions on the New Issue page which direct you to StackOverflow (the question asking/answering site). If you find the answer, hopefully it works for you. If you discover that you need me to expose more of the Android API in this plugin, you can come back here and submit a feature request detailing exactly what parts of the API are missing.

rd-wang commented 3 days ago

If you want to ask a question about how set the icons on Android, please follow the instructions on the New Issue page which direct you to StackOverflow (the question asking/answering site). If you find the answer, hopefully it works for you. If you discover that you need me to expose more of the Android API in this plugin, you can come back here and submit a feature request detailing exactly what parts of the API are missing.

this is a problem

when i clear controls setting or not set controls

PlaybackState( controls:[], ... ) PlaybackState( ... )

there is a default pause and play icon in notification

this is because com/ryanheise/audioservice/AudioService.java line 75 AUTO_ENABLED_ACTIONS set bitmask of the available capabilities. | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE remove this bitmask
there is no controls in notification match the empty controls setting or not set controls