From 176126bac00d7e2ba0563bdd5d9dc045af94c616 Mon Sep 17 00:00:00 2001 From: Thomas Bono Date: Fri, 23 Aug 2024 13:19:24 -0400 Subject: [PATCH 1/5] adding setVolume hooks, web done --- README.md | 14 ++++++++++++++ src/definitions.ts | 1 + src/web.ts | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 6e09dad..4a66388 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ npx cap sync * [`resume()`](#resume) * [`seekTo(...)`](#seekto) * [`stop()`](#stop) +* [`setVolume(...)`](#setvolume) * [`setPlaybackRate(...)`](#setplaybackrate) * [`setNowPlayingInfo(...)`](#setnowplayinginfo) * [`addListener('error' | 'play' | 'pause' | 'stop' | 'timeUpdate' | 'buffering', ...)`](#addlistenererror--play--pause--stop--timeupdate--buffering-) @@ -83,6 +84,19 @@ stop() => Promise -------------------- +### setVolume(...) + +```typescript +setVolume(options: { volume: number; }) => Promise +``` + +| Param | Type | +| ------------- | -------------------------------- | +| **`options`** | { volume: number; } | + +-------------------- + + ### setPlaybackRate(...) ```typescript diff --git a/src/definitions.ts b/src/definitions.ts index 849e298..d23c350 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -6,6 +6,7 @@ export interface RemoteStreamerPlugin { resume(): Promise; seekTo(options: { position: number }): Promise; stop(): Promise; + setVolume(options: { volume: number }): Promise; setPlaybackRate(options: { rate: number }): Promise; setNowPlayingInfo(options: { title: string; artist: string; album: string; duration: string; imageUrl: string; isLiveStream: boolean }): Promise; addListener( diff --git a/src/web.ts b/src/web.ts index ffff7da..7366d24 100644 --- a/src/web.ts +++ b/src/web.ts @@ -76,6 +76,12 @@ export class RemoteStreamerWeb extends WebPlugin implements RemoteStreamerPlugin } } + async setVolume(options: { volume: number }): Promise { + if (this.audio) { + this.audio.volume = options.volume; + } + } + private setupEventListeners() { if (this.audio) { this.audio.onplaying = () => this.notifyListeners('play', {}); From 239b8693491ec1c370b3331ab6720c4fccf14281 Mon Sep 17 00:00:00 2001 From: Thomas Bono Date: Fri, 23 Aug 2024 13:59:10 -0400 Subject: [PATCH 2/5] trying to add setVolume to Android.. and failing --- .../co/broadcastapp/muckabout/RemoteStreamerPlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java b/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java index a54d0bf..e7eb1ca 100644 --- a/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java +++ b/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java @@ -363,6 +363,13 @@ public void onAudioFocusChange(int focusChange) { }); } + @PluginMethod + public void setVolume(PluginCall call) throws JSONException { + Float volume; + volume = (float) call.getData().getDouble("volume"); + player.setVolume(volume); + call.resolve(); + } public void actionCallback(String action) { actionCallback(action, new JSObject()); From 0f9c61a9f078bebf41627e9db7ed80cb5020aa74 Mon Sep 17 00:00:00 2001 From: Thomas Bono Date: Sat, 24 Aug 2024 16:49:56 -0400 Subject: [PATCH 3/5] android fade out works --- .../muckabout/RemoteStreamerPlugin.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java b/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java index e7eb1ca..215e15a 100644 --- a/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java +++ b/android/src/main/java/co/broadcastapp/muckabout/RemoteStreamerPlugin.java @@ -364,11 +364,16 @@ public void onAudioFocusChange(int focusChange) { } @PluginMethod - public void setVolume(PluginCall call) throws JSONException { - Float volume; - volume = (float) call.getData().getDouble("volume"); - player.setVolume(volume); - call.resolve(); + public void setVolume(PluginCall call) { + handler.post(() -> { + Float volume; + try { + volume = (float) call.getData().getDouble("volume"); + } catch (JSONException e) { + throw new RuntimeException(e); + } + player.setVolume(volume); + }); } public void actionCallback(String action) { From 368b57199258879c22b057fb0c460bf1db4a6b96 Mon Sep 17 00:00:00 2001 From: Thomas Bono Date: Sat, 24 Aug 2024 17:00:12 -0400 Subject: [PATCH 4/5] ios support for setVColume testing --- ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift | 4 ++++ .../RemoteStreamerPlugin/RemoteStreamerPlugin.swift | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift b/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift index 05bb337..cb5edce 100644 --- a/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift +++ b/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift @@ -144,6 +144,10 @@ class RemoteStreamer: NSObject { NotificationCenter.default.post(name: Notification.Name("RemoteStreamerTimeUpdate"), object: nil, userInfo: ["currentTime": time]) } + private func setVolume(volume: Double) { + NotificationCenter.default.post(name: Notification.Name("RemoteStreamerSetVolume"), object: nil, userInfo: ["volume": volume]) + } + @objc private func playerDidFinishPlaying(note: NSNotification) { NotificationCenter.default.post(name: Notification.Name("RemoteStreamerEnded"), object: nil, userInfo: ["ended": true]) diff --git a/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift b/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift index 9563561..469f2a2 100644 --- a/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift +++ b/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift @@ -13,6 +13,7 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { CAPPluginMethod(name: "stop", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "seekTo", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "setNowPlayingInfo", returnType: CAPPluginReturnPromise) + CAPPluginMethod(name: "setVolume", returnType: CAPPluginReturnPromise) ] private let implementation = RemoteStreamer() @@ -23,6 +24,7 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { NotificationCenter.default.addObserver(self, selector: #selector(handleStopEvent), name: Notification.Name("RemoteStreamerStop"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleEndedEvent), name: Notification.Name("RemoteStreamerEnded"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimeUpdateEvent), name: Notification.Name("RemoteStreamerTimeUpdate"), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleSetVolumeEvent), name: Notification.Name("RemoteStreamerSetVolume"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleBufferingEvent), name: Notification.Name("RemoteStreamerBuffering"), object: nil) setupRemoteTransportControls() } @@ -112,6 +114,12 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { call.resolve() } + @objc func handleSetVolumeEvent(_ call: CAPPluginCall) { + print("set volume") + implementation.setVolume(call.getFloat("volume") ?? 1.0) + call.resolve() + } + @objc func seekTo(_ call: CAPPluginCall) { guard let position = call.getDouble("position") else { call.reject("Must provide a position") From 5a20e09b7b5699364d4cb5f9f601038ab4345dca Mon Sep 17 00:00:00 2001 From: Digital Date: Sat, 24 Aug 2024 17:23:28 -0400 Subject: [PATCH 5/5] ios fading out now --- ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift | 5 +++-- .../RemoteStreamerPlugin/RemoteStreamerPlugin.swift | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift b/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift index cb5edce..724ac65 100644 --- a/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift +++ b/ios/Sources/RemoteStreamerPlugin/RemoteStreamer.swift @@ -144,8 +144,9 @@ class RemoteStreamer: NSObject { NotificationCenter.default.post(name: Notification.Name("RemoteStreamerTimeUpdate"), object: nil, userInfo: ["currentTime": time]) } - private func setVolume(volume: Double) { - NotificationCenter.default.post(name: Notification.Name("RemoteStreamerSetVolume"), object: nil, userInfo: ["volume": volume]) + func setVolume(volume: Double) { + //player?.setVolume({volume}) + player?.volume = Float(volume) } @objc private func playerDidFinishPlaying(note: NSNotification) { diff --git a/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift b/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift index 469f2a2..5160cd3 100644 --- a/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift +++ b/ios/Sources/RemoteStreamerPlugin/RemoteStreamerPlugin.swift @@ -12,7 +12,7 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { CAPPluginMethod(name: "resume", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "stop", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "seekTo", returnType: CAPPluginReturnPromise), - CAPPluginMethod(name: "setNowPlayingInfo", returnType: CAPPluginReturnPromise) + CAPPluginMethod(name: "setNowPlayingInfo", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "setVolume", returnType: CAPPluginReturnPromise) ] @@ -24,7 +24,6 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { NotificationCenter.default.addObserver(self, selector: #selector(handleStopEvent), name: Notification.Name("RemoteStreamerStop"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleEndedEvent), name: Notification.Name("RemoteStreamerEnded"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimeUpdateEvent), name: Notification.Name("RemoteStreamerTimeUpdate"), object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(handleSetVolumeEvent), name: Notification.Name("RemoteStreamerSetVolume"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleBufferingEvent), name: Notification.Name("RemoteStreamerBuffering"), object: nil) setupRemoteTransportControls() } @@ -114,9 +113,9 @@ public class RemoteStreamerPlugin: CAPPlugin, CAPBridgedPlugin { call.resolve() } - @objc func handleSetVolumeEvent(_ call: CAPPluginCall) { + @objc func setVolume(_ call: CAPPluginCall) { print("set volume") - implementation.setVolume(call.getFloat("volume") ?? 1.0) + implementation.setVolume(volume: call.getDouble("volume")!) call.resolve() }