@capgo/native-audio 8.3.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,7 +12,7 @@ enum MyError: Error {
|
|
|
12
12
|
@objc(NativeAudio)
|
|
13
13
|
// swiftlint:disable:next type_body_length
|
|
14
14
|
public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
|
|
15
|
-
private let pluginVersion: String = "8.3.
|
|
15
|
+
private let pluginVersion: String = "8.3.1"
|
|
16
16
|
public let identifier = "NativeAudio"
|
|
17
17
|
public let jsName = "NativeAudio"
|
|
18
18
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -640,10 +640,21 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
|
|
|
640
640
|
|
|
641
641
|
public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
|
|
642
642
|
// Don't immediately end the session here, as other players might still be active
|
|
643
|
-
// Instead, check if all players are done
|
|
643
|
+
// Instead, check if all players are done and clear Now Playing if this asset was current
|
|
644
644
|
audioQueue.async { [weak self] in
|
|
645
645
|
guard let self = self else { return }
|
|
646
646
|
|
|
647
|
+
// Find which asset this player belongs to; if it was the currently playing one, clear notification
|
|
648
|
+
for (audioId, asset) in self.audioList {
|
|
649
|
+
if let audioAsset = asset as? AudioAsset, audioAsset.channels.contains(player) {
|
|
650
|
+
if self.currentlyPlayingAssetId == audioId {
|
|
651
|
+
self.currentlyPlayingAssetId = nil
|
|
652
|
+
self.clearNowPlayingInfo()
|
|
653
|
+
}
|
|
654
|
+
break
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
647
658
|
// Avoid recursive calls by checking if the asset is still in the list
|
|
648
659
|
let hasPlayingAssets = self.audioList.values.contains { asset in
|
|
649
660
|
if let audioAsset = asset as? AudioAsset {
|
|
@@ -655,6 +666,11 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
|
|
|
655
666
|
|
|
656
667
|
// Only end the session if no more assets are playing
|
|
657
668
|
if !hasPlayingAssets {
|
|
669
|
+
// If we didn't find the asset above (e.g. playOnce already removed it), clear notification when nothing is playing
|
|
670
|
+
if self.currentlyPlayingAssetId != nil {
|
|
671
|
+
self.currentlyPlayingAssetId = nil
|
|
672
|
+
self.clearNowPlayingInfo()
|
|
673
|
+
}
|
|
658
674
|
self.endSession()
|
|
659
675
|
}
|
|
660
676
|
}
|