@capgo/native-audio 8.3.17 → 8.3.18
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.
- package/android/src/main/java/ee/forgr/audio/AudioAsset.java +2 -0
- package/android/src/main/java/ee/forgr/audio/RemoteAudioAsset.java +22 -2
- package/ios/Sources/NativeAudioPlugin/AudioAsset+Fade.swift +4 -2
- package/ios/Sources/NativeAudioPlugin/Plugin.swift +1 -1
- package/ios/Sources/NativeAudioPlugin/RemoteAudioAsset+Fade.swift +4 -2
- package/package.json +1 -1
|
@@ -612,8 +612,16 @@ public class RemoteAudioAsset extends AudioAsset {
|
|
|
612
612
|
);
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
+
@Override
|
|
616
|
+
public void stopWithFade(double fadeOutDurationMs, boolean toPause) throws Exception {
|
|
617
|
+
stopWithFade((float) fadeOutDurationMs, toPause);
|
|
618
|
+
}
|
|
619
|
+
|
|
615
620
|
public void stopWithFade(float fadeOutDurationMs, boolean asPause) throws Exception {
|
|
616
621
|
if (players.isEmpty()) {
|
|
622
|
+
if (!asPause) {
|
|
623
|
+
stop();
|
|
624
|
+
}
|
|
617
625
|
return;
|
|
618
626
|
}
|
|
619
627
|
|
|
@@ -623,6 +631,12 @@ public class RemoteAudioAsset extends AudioAsset {
|
|
|
623
631
|
.runOnUiThread(() -> {
|
|
624
632
|
if (player != null && player.isPlaying()) {
|
|
625
633
|
fadeOut(player, fadeOutDurationMs, asPause);
|
|
634
|
+
} else if (!asPause) {
|
|
635
|
+
try {
|
|
636
|
+
stop();
|
|
637
|
+
} catch (Exception e) {
|
|
638
|
+
logger.error("Error stopping remote audio after failed fade", e);
|
|
639
|
+
}
|
|
626
640
|
}
|
|
627
641
|
});
|
|
628
642
|
}
|
|
@@ -661,13 +675,19 @@ public class RemoteAudioAsset extends AudioAsset {
|
|
|
661
675
|
owner
|
|
662
676
|
.getActivity()
|
|
663
677
|
.runOnUiThread(() -> {
|
|
664
|
-
|
|
678
|
+
// Stop/pause unconditionally: the fade brought volume to zero so the
|
|
679
|
+
// player must be stopped regardless of its current isPlaying() state
|
|
680
|
+
// (e.g. ExoPlayer may have auto-stopped at volume 0 on some devices).
|
|
681
|
+
if (player != null) {
|
|
665
682
|
if (asPause) {
|
|
666
683
|
player.pause();
|
|
667
684
|
logger.verbose("Faded out to pause at time " + getCurrentPosition());
|
|
668
685
|
} else {
|
|
669
686
|
player.setVolume(0);
|
|
670
687
|
player.stop();
|
|
688
|
+
dispatchComplete();
|
|
689
|
+
initializePlayer(player);
|
|
690
|
+
isPrepared = false;
|
|
671
691
|
logger.verbose("Faded out to stop at time " + getCurrentPosition());
|
|
672
692
|
}
|
|
673
693
|
}
|
|
@@ -685,7 +705,7 @@ public class RemoteAudioAsset extends AudioAsset {
|
|
|
685
705
|
owner
|
|
686
706
|
.getActivity()
|
|
687
707
|
.runOnUiThread(() -> {
|
|
688
|
-
if (player != null
|
|
708
|
+
if (player != null) {
|
|
689
709
|
player.setVolume(thisTargetVolume);
|
|
690
710
|
}
|
|
691
711
|
});
|
|
@@ -87,7 +87,7 @@ extension AudioAsset {
|
|
|
87
87
|
beforePause: ((TimeInterval, TimeInterval) -> Void)? = nil
|
|
88
88
|
) {
|
|
89
89
|
cancelFade()
|
|
90
|
-
let steps = Int(fadeOutDuration / TimeInterval(fadeDelaySecs))
|
|
90
|
+
let steps = max(0, Int(fadeOutDuration / TimeInterval(fadeDelaySecs)))
|
|
91
91
|
guard steps > 0 else {
|
|
92
92
|
if toPause {
|
|
93
93
|
scheduleLocalFadeOutPauseOnMain(audio: audio, beforePause: beforePause)
|
|
@@ -103,13 +103,15 @@ extension AudioAsset {
|
|
|
103
103
|
task = DispatchWorkItem { [weak self] in
|
|
104
104
|
guard let self else { return }
|
|
105
105
|
for _ in 0..<steps {
|
|
106
|
-
guard let task, !task.isCancelled
|
|
106
|
+
guard let task, !task.isCancelled else { return }
|
|
107
|
+
guard self.isPlaying(), audio.isPlaying else { break }
|
|
107
108
|
currentVolume -= fadeStep
|
|
108
109
|
DispatchQueue.main.async {
|
|
109
110
|
audio.volume = max(currentVolume, 0)
|
|
110
111
|
}
|
|
111
112
|
Thread.sleep(forTimeInterval: TimeInterval(self.fadeDelaySecs))
|
|
112
113
|
}
|
|
114
|
+
guard let task, !task.isCancelled else { return }
|
|
113
115
|
DispatchQueue.main.async { [weak self] in
|
|
114
116
|
guard let self else { return }
|
|
115
117
|
if toPause {
|
|
@@ -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.18"
|
|
16
16
|
public let identifier = "NativeAudio"
|
|
17
17
|
public let jsName = "NativeAudio"
|
|
18
18
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -62,7 +62,7 @@ extension RemoteAudioAsset {
|
|
|
62
62
|
beforePause: ((TimeInterval, TimeInterval) -> Void)? = nil
|
|
63
63
|
) {
|
|
64
64
|
cancelFade()
|
|
65
|
-
let steps = Int(fadeOutDuration / TimeInterval(fadeDelaySecs))
|
|
65
|
+
let steps = max(0, Int(fadeOutDuration / TimeInterval(fadeDelaySecs)))
|
|
66
66
|
guard steps > 0 else {
|
|
67
67
|
if toPause {
|
|
68
68
|
scheduleRemoteFadeOutPauseOnMain(player: player, beforePause: beforePause)
|
|
@@ -81,13 +81,15 @@ extension RemoteAudioAsset {
|
|
|
81
81
|
task = DispatchWorkItem { [weak self] in
|
|
82
82
|
guard let self else { return }
|
|
83
83
|
for _ in 0..<steps {
|
|
84
|
-
guard let task, !task.isCancelled
|
|
84
|
+
guard let task, !task.isCancelled else { return }
|
|
85
|
+
guard self.isPlaying(), player.timeControlStatus == .playing else { break }
|
|
85
86
|
currentVolume -= fadeStep
|
|
86
87
|
DispatchQueue.main.async {
|
|
87
88
|
player.volume = max(currentVolume, 0)
|
|
88
89
|
}
|
|
89
90
|
Thread.sleep(forTimeInterval: TimeInterval(self.fadeDelaySecs))
|
|
90
91
|
}
|
|
92
|
+
guard let task, !task.isCancelled else { return }
|
|
91
93
|
DispatchQueue.main.async { [weak self] in
|
|
92
94
|
guard let self else { return }
|
|
93
95
|
if toPause {
|