From da44b086b18ce854384ef2244166640003bc5a45 Mon Sep 17 00:00:00 2001 From: Haim Omesi <32476571+haimomesi@users.noreply.github.com> Date: Thu, 29 Jul 2021 18:15:52 +0300 Subject: [PATCH 1/2] Update AudioDispatcher.java Actually play the file --- .../java/com/getcapacitor/community/audio/AudioDispatcher.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/getcapacitor/community/audio/AudioDispatcher.java b/android/src/main/java/com/getcapacitor/community/audio/AudioDispatcher.java index 666ce5c..d2c5c82 100644 --- a/android/src/main/java/com/getcapacitor/community/audio/AudioDispatcher.java +++ b/android/src/main/java/com/getcapacitor/community/audio/AudioDispatcher.java @@ -92,6 +92,7 @@ public void setVolume(float volume) throws Exception { public void loop() throws Exception { mediaPlayer.setLooping(true); + invokePlay(0.0, true); } public void unload() throws Exception { From 94dfe9f79cb41d77c9471bf60f6e56c97193bd49 Mon Sep 17 00:00:00 2001 From: Haim Omesi <32476571+haimomesi@users.noreply.github.com> Date: Tue, 10 Aug 2021 20:18:32 +0300 Subject: [PATCH 2/2] Update setCategory on each action This will prevent from other processes to drop sound --- ios/Plugin/Plugin.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 206caad..ee4df45 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -42,6 +42,14 @@ public class NativeAudio: CAPPlugin { } @objc func play(_ call: CAPPluginCall) { + + do { + let session = AVAudioSession.sharedInstance() + try session.setCategory(AVAudioSession.Category.playback, options: .mixWithOthers) + } catch{ + print("Couldnt set AudioSession") + } + let audioId = call.getString(Constant.AssetIdKey) ?? "" let time = call.getDouble("time") ?? 0 if audioId != "" { @@ -137,6 +145,9 @@ public class NativeAudio: CAPPlugin { do { try stopAudio(audioId: audioId) + let session = AVAudioSession.sharedInstance() + try session.setCategory(AVAudioSession.Category.ambient, options: .mixWithOthers) + call.success() } catch { call.error(Constant.ErrorAssetNotFound) } @@ -147,6 +158,13 @@ public class NativeAudio: CAPPlugin { return } + do{ + let session = AVAudioSession.sharedInstance() + try session.setCategory(AVAudioSession.Category.playback, options: .mixWithOthers) + } catch{ + print("Couldnt set AudioSession") + } + audioAsset.loop() call.success() }