Skip to content

Commit

Permalink
Keep notification when audio's over
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Jan 15, 2024
1 parent 2ef22d3 commit 566003e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class AlarmService : Service() {

audioService?.setOnAudioCompleteListener {
if (!loopAudio!!) {
stopAlarm(id)
vibrationService?.stopVibrating()
volumeService?.restorePreviousVolume(showSystemUI)
volumeService?.abandonAudioFocus()
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_fgbg: 31c0d1140a131daea2d342121808f6aa0dcd879d
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.14.2
COCOAPODS: 1.14.3
10 changes: 6 additions & 4 deletions ios/Classes/SwiftAlarmPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {
self.setAlarm(call: call, result: result)
} else if call.method == "stopAlarm" {
if let args = call.arguments as? [String: Any], let id = args["id"] as? Int {
self.stopAlarm(id: id, result: result)
self.stopAlarm(id: id, cancelNotif: true, result: result)
} else {
result(FlutterError.init(code: "NATIVE_ERR", message: "[Alarm] Error: id parameter is missing or invalid", details: nil))
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {
if !audioLoop {
let audioDuration = audioPlayer.duration
DispatchQueue.main.asyncAfter(deadline: .now() + audioDuration) {
self.stopAlarm(id: id, result: { _ in })
self.stopAlarm(id: id, cancelNotif: false, result: { _ in })
}
}

Expand All @@ -263,8 +263,10 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {
}
}

private func stopAlarm(id: Int, result: FlutterResult) {
self.cancelNotification(id: String(id))
private func stopAlarm(id: Int, cancelNotif: Bool, result: FlutterResult) {
if cancelNotif {
self.cancelNotification(id: String(id))
}

self.mixOtherAudios()

Expand Down

0 comments on commit 566003e

Please sign in to comment.