@capgo/native-audio
Advanced tools
@@ -428,2 +428,4 @@ package ee.forgr.audio; | ||
| fadeOut(audio, fadeOutDurationMs, toPause); | ||
| } else if (!toPause) { | ||
| stop(); | ||
| } | ||
@@ -430,0 +432,0 @@ } |
@@ -615,4 +615,12 @@ package ee.forgr.audio; | ||
| @Override | ||
| public void stopWithFade(double fadeOutDurationMs, boolean toPause) throws Exception { | ||
| stopWithFade((float) fadeOutDurationMs, toPause); | ||
| } | ||
| public void stopWithFade(float fadeOutDurationMs, boolean asPause) throws Exception { | ||
| if (players.isEmpty()) { | ||
| if (!asPause) { | ||
| stop(); | ||
| } | ||
| return; | ||
@@ -627,2 +635,8 @@ } | ||
| fadeOut(player, fadeOutDurationMs, asPause); | ||
| } else if (!asPause) { | ||
| try { | ||
| stop(); | ||
| } catch (Exception e) { | ||
| logger.error("Error stopping remote audio after failed fade", e); | ||
| } | ||
| } | ||
@@ -666,3 +680,6 @@ }); | ||
| .runOnUiThread(() -> { | ||
| if (player != null && player.isPlaying()) { | ||
| // Stop/pause unconditionally: the fade brought volume to zero so the | ||
| // player must be stopped regardless of its current isPlaying() state | ||
| // (e.g. ExoPlayer may have auto-stopped at volume 0 on some devices). | ||
| if (player != null) { | ||
| if (asPause) { | ||
@@ -674,2 +691,5 @@ player.pause(); | ||
| player.stop(); | ||
| dispatchComplete(); | ||
| initializePlayer(player); | ||
| isPrepared = false; | ||
| logger.verbose("Faded out to stop at time " + getCurrentPosition()); | ||
@@ -692,3 +712,3 @@ } | ||
| .runOnUiThread(() -> { | ||
| if (player != null && player.isPlaying()) { | ||
| if (player != null) { | ||
| player.setVolume(thisTargetVolume); | ||
@@ -695,0 +715,0 @@ } |
@@ -90,3 +90,3 @@ import AVFoundation | ||
| cancelFade() | ||
| let steps = Int(fadeOutDuration / TimeInterval(fadeDelaySecs)) | ||
| let steps = max(0, Int(fadeOutDuration / TimeInterval(fadeDelaySecs))) | ||
| guard steps > 0 else { | ||
@@ -107,3 +107,4 @@ if toPause { | ||
| for _ in 0..<steps { | ||
| guard let task, !task.isCancelled, self.isPlaying(), audio.isPlaying else { return } | ||
| guard let task, !task.isCancelled else { return } | ||
| guard self.isPlaying(), audio.isPlaying else { break } | ||
| currentVolume -= fadeStep | ||
@@ -115,2 +116,3 @@ DispatchQueue.main.async { | ||
| } | ||
| guard let task, !task.isCancelled else { return } | ||
| DispatchQueue.main.async { [weak self] in | ||
@@ -117,0 +119,0 @@ guard let self else { return } |
@@ -65,3 +65,3 @@ import AVFoundation | ||
| cancelFade() | ||
| let steps = Int(fadeOutDuration / TimeInterval(fadeDelaySecs)) | ||
| let steps = max(0, Int(fadeOutDuration / TimeInterval(fadeDelaySecs))) | ||
| guard steps > 0 else { | ||
@@ -85,3 +85,4 @@ if toPause { | ||
| for _ in 0..<steps { | ||
| guard let task, !task.isCancelled, self.isPlaying(), player.timeControlStatus == .playing else { return } | ||
| guard let task, !task.isCancelled else { return } | ||
| guard self.isPlaying(), player.timeControlStatus == .playing else { break } | ||
| currentVolume -= fadeStep | ||
@@ -93,2 +94,3 @@ DispatchQueue.main.async { | ||
| } | ||
| guard let task, !task.isCancelled else { return } | ||
| DispatchQueue.main.async { [weak self] in | ||
@@ -95,0 +97,0 @@ guard let self else { return } |
+1
-1
| { | ||
| "name": "@capgo/native-audio", | ||
| "version": "8.3.17", | ||
| "version": "8.3.18", | ||
| "description": "A native plugin for native audio engine", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
Sorry, the diff of this file is too big to display
695819
0.17%7910
0.27%