Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

[ New Feature ] Custom notif Android/ios

Open florent37 opened this issue 5 years ago • 10 comments

Same interractions on Android & ios :

settings: NotificationSettings.multiplatform(
  prev: NotificationActionsPrev.prev(),
  playPause: null, //to disable it
  next: NotificationActionsNext.next(
      customAction: (player) {
           //action
      }
  ),
  stop: NotificationActions.stop(),
)

florent37 avatar Jun 23 '20 14:06 florent37

Custom notif on platforms

settings: NotificationSettings.perPlatform(
    android: AndroidNotification(

        // because you can have up to 4 actions

        action1: NotificationActionsPrev.prev()
        action2:  NotificationActions.playPause(),
        action3:  NotificationActionsNext.next(),
        action4:  NotificationActions.stop(),
    ),
    ios: iOSNotification(
          prev: NotificationActionsPrev.prev()
          playPause: null, //to disable it
          next: NotificationActionsNext.next(),
          stop: NotificationActions.stop(),
    )
)

florent37 avatar Jun 23 '20 14:06 florent37

Custom notif on platforms

settings: NotificationSettings.perPlatform(
    android: AndroidNotification(
        action1: NotificationActions.playPause(
              customAction: (player) {
                        //action
              }
        ),
    ),
    ios: iOSNotification(
          playPause: NotificationActions.playPause(
                  customAction: (player) {
                        //action
                 }
          ),
    )
)

florent37 avatar Jun 23 '20 14:06 florent37

Custom action & custom icon Android

eg: custom icon (heart)

settings: NotificationSettings.perPlatform(
    android: AndroidNotification(

        action1:  NotificationActions.custom(
          iconBuilder: (player, currentAudio) {
            if(isFavorite(currentAudio.path)){
              return AndroidDrawable("ic_fav_full");
            } else {
              return AndroidDrawable("ic_fav_empty");
            }
          }
          customAction: (player, currentAudio, notification) {
            //action
            toggleIsFavorite(currentAudio.path);
            notification.updateIcon(); //will call iconBuilder
          }
        ),

    )
)

florent37 avatar Jun 23 '20 14:06 florent37

seek instead of prev action

(on android, I need to find how to handle the icon)

settings: NotificationSettings.perPlatform(
    android: AndroidNotification(
        //eg: seek in place of prev
        action1:  NotificationActionsPrev.seek(by: Duration(seconds: 10)),

    ),
    ios: iOSNotification(
          //eg: seek in place of prev
          prev: NotificationActionsPrev.seek(by: Duration(seconds: 10)),
    )
)

florent37 avatar Jun 23 '20 14:06 florent37

I don't know if you already find out this sample code by Apple but I think I could be helping for this issue: https://developer.apple.com/documentation/mediaplayer/becoming_a_now_playable_app

It list all command possible with a control center as a sample app for iPhone. Really useful to test and see what's possible and what's not

chevalierv avatar Jun 23 '20 19:06 chevalierv

oh

NowPlayableCommand

case pause, play, stop, togglePausePlay
case nextTrack, previousTrack, changeRepeatMode, changeShuffleMode
case changePlaybackRate, seekBackward, seekForward, skipBackward, skipForward, changePlaybackPosition
case rating, like, dislike
case bookmark
case enableLanguageOption, disableLanguageOption

florent37 avatar Jun 24 '20 14:06 florent37

https://stackoverflow.com/questions/20591156/is-there-a-public-way-to-force-mpnowplayinginfocenter-to-show-podcast-controls

For seek :

import MediaPlayer

let rcc = MPRemoteCommandCenter.shared()

let skipBackwardCommand = rcc.skipBackwardCommand
skipBackwardCommand.isEnabled = true
skipBackwardCommand.addTarget(handler: skipBackward)
skipBackwardCommand.preferredIntervals = [42]

let skipForwardCommand = rcc.skipForwardCommand
skipForwardCommand.isEnabled = true
skipForwardCommand.addTarget(handler: skipForward)
skipForwardCommand.preferredIntervals = [42]

func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
    guard let command = event.command as? MPSkipIntervalCommand else {
        return .noSuchContent
    }

    let interval = command.preferredIntervals[0]

    print(interval) //Output: 42

    return .success
}

func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
    guard let command = event.command as? MPSkipIntervalCommand else {
        return .noSuchContent
    }

    let interval = command.preferredIntervals[0]

    print(interval) //Output: 42

    return .success
}

florent37 avatar Jun 24 '20 14:06 florent37

was this merged?

colindotfun avatar Feb 22 '21 15:02 colindotfun

was this merged?

same question, it would be awesome to custom iOS notifications :)

swifthing avatar Feb 26 '22 22:02 swifthing

The latest version still doesn’t work.

tudosxxx avatar Nov 21 '23 08:11 tudosxxx