Open florent37 opened 4 years ago
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(),
)
)
settings: NotificationSettings.perPlatform(
android: AndroidNotification(
action1: NotificationActions.playPause(
customAction: (player) {
//action
}
),
),
ios: iOSNotification(
playPause: NotificationActions.playPause(
customAction: (player) {
//action
}
),
)
)
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
}
),
)
)
(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)),
)
)
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
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
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
}
was this merged?
was this merged?
same question, it would be awesome to custom iOS notifications :)
The latest version still doesn’t work.
Same interractions on Android & ios :