@capgo/capacitor-audio-session 8.0.1 → 8.0.2
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.
|
@@ -16,7 +16,7 @@ import org.json.JSONObject;
|
|
|
16
16
|
|
|
17
17
|
@CapacitorPlugin(name = "AudioSession")
|
|
18
18
|
public class AudioSessionPlugin extends Plugin {
|
|
19
|
-
private final String pluginVersion = "8.0.
|
|
19
|
+
private final String pluginVersion = "8.0.2";
|
|
20
20
|
|
|
21
21
|
public static String LOG_TAG = "CapgoAudioSession";
|
|
22
22
|
|
|
@@ -2,12 +2,12 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import AVKit
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var audioSessionOverrideTypes: [AVAudioSession.PortOverride: String] = [
|
|
6
6
|
.none: "none",
|
|
7
7
|
.speaker: "speaker"
|
|
8
8
|
]
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var audioSessionRouteChangeReasons: [AVAudioSession.RouteChangeReason: String] = [
|
|
11
11
|
.newDeviceAvailable: "new-device-available",
|
|
12
12
|
.oldDeviceUnavailable: "old-device-unavailable",
|
|
13
13
|
.categoryChange: "category-change",
|
|
@@ -18,12 +18,12 @@ var AudioSessionRouteChangeReasons: [AVAudioSession.RouteChangeReason: String] =
|
|
|
18
18
|
.unknown: "unknown"
|
|
19
19
|
]
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var audioSessionInterruptionTypes: [AVAudioSession.InterruptionType: String] = [
|
|
22
22
|
.began: "began",
|
|
23
23
|
.ended: "ended"
|
|
24
24
|
]
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var audioSessionPorts: [AVAudioSession.Port: String] = [
|
|
27
27
|
.airPlay: "airplay",
|
|
28
28
|
.bluetoothLE: "bluetooth-le",
|
|
29
29
|
.bluetoothHFP: "bluetooth-hfp",
|
|
@@ -47,14 +47,14 @@ public class AudioSession: NSObject {
|
|
|
47
47
|
var currentOverride: String?
|
|
48
48
|
|
|
49
49
|
public func load() {
|
|
50
|
-
let
|
|
50
|
+
let notificationCenter = NotificationCenter.default
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
notificationCenter.addObserver(self,
|
|
53
53
|
selector: #selector(self.handleRouteChange),
|
|
54
54
|
name: AVAudioSession.routeChangeNotification,
|
|
55
55
|
object: nil)
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
notificationCenter.addObserver(self,
|
|
58
58
|
selector: #selector(self.handleInterruption),
|
|
59
59
|
name: AVAudioSession.interruptionNotification,
|
|
60
60
|
object: AVAudioSession.sharedInstance)
|
|
@@ -66,7 +66,7 @@ public class AudioSession: NSObject {
|
|
|
66
66
|
guard let userInfo = notification.userInfo,
|
|
67
67
|
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
|
|
68
68
|
let reasonType = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else { return }
|
|
69
|
-
let readableReason =
|
|
69
|
+
let readableReason = audioSessionRouteChangeReasons[reasonType] ?? "unknown"
|
|
70
70
|
|
|
71
71
|
CAPLog.print("AudioSession.handleRouteChange() changed to \(readableReason)")
|
|
72
72
|
|
|
@@ -77,7 +77,7 @@ public class AudioSession: NSObject {
|
|
|
77
77
|
guard let userInfo = notification.userInfo,
|
|
78
78
|
let interruptValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
|
|
79
79
|
let interruptType = AVAudioSession.InterruptionType(rawValue: interruptValue) else { return }
|
|
80
|
-
let readableInterrupt =
|
|
80
|
+
let readableInterrupt = audioSessionInterruptionTypes[interruptType] ?? "unknown"
|
|
81
81
|
|
|
82
82
|
CAPLog.print("AudioSession.handleInterruption() interrupted status to \(readableInterrupt)")
|
|
83
83
|
|
|
@@ -87,18 +87,18 @@ public class AudioSession: NSObject {
|
|
|
87
87
|
// METHODS
|
|
88
88
|
|
|
89
89
|
public func currentOutputs() -> [String?] {
|
|
90
|
-
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs.map({
|
|
90
|
+
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs.map({audioSessionPorts[$0.portType]})
|
|
91
91
|
|
|
92
92
|
return outputs
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
public func overrideOutput(
|
|
96
|
-
if
|
|
97
|
-
return
|
|
95
|
+
public func overrideOutput(output: String, callback: @escaping AudioSessionOverrideCallback) {
|
|
96
|
+
if output == "unknown" {
|
|
97
|
+
return callback(false, "No valid output provided...", nil)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
if self.currentOverride ==
|
|
101
|
-
return
|
|
100
|
+
if self.currentOverride == output {
|
|
101
|
+
return callback(true, nil, nil)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// make it async, cause in latest IOS it started to take ~1 sec and produce UI thread blocking issues
|
|
@@ -111,25 +111,25 @@ public class AudioSession: NSObject {
|
|
|
111
111
|
try session.setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.duckOthers)
|
|
112
112
|
} catch {
|
|
113
113
|
CAPLog.print("AudioSession.overrideOutput() error setting sessions settings.")
|
|
114
|
-
|
|
114
|
+
callback(false, "Error setting sessions settings.", true)
|
|
115
115
|
return
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
do {
|
|
119
|
-
if
|
|
119
|
+
if output == "speaker" {
|
|
120
120
|
try session.overrideOutputAudioPort(.speaker)
|
|
121
121
|
} else {
|
|
122
122
|
try session.overrideOutputAudioPort(.none)
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
self.currentOverride =
|
|
125
|
+
self.currentOverride = output
|
|
126
126
|
|
|
127
|
-
CAPLog.print("currentOverride: " + (self.currentOverride ?? "") + " - " +
|
|
127
|
+
CAPLog.print("currentOverride: " + (self.currentOverride ?? "") + " - " + output)
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
callback(true, nil, nil)
|
|
130
130
|
} catch {
|
|
131
131
|
CAPLog.print("AudioSession.overrideOutput() could not override output port.")
|
|
132
|
-
|
|
132
|
+
callback(false, "Could not override output port.", true)
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -3,7 +3,7 @@ import Capacitor
|
|
|
3
3
|
|
|
4
4
|
@objc(AudioSessionPlugin)
|
|
5
5
|
public class AudioSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
-
private let pluginVersion: String = "8.0.
|
|
6
|
+
private let pluginVersion: String = "8.0.2"
|
|
7
7
|
public let identifier = "AudioSessionPlugin"
|
|
8
8
|
public let jsName = "AudioSession"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -41,7 +41,7 @@ public class AudioSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
41
41
|
@objc func overrideOutput(_ call: CAPPluginCall) {
|
|
42
42
|
let output = call.getString("type") ?? "unknown"
|
|
43
43
|
|
|
44
|
-
implementation.overrideOutput(
|
|
44
|
+
implementation.overrideOutput(output: output, callback: { (success, message, error) in
|
|
45
45
|
if error == true {
|
|
46
46
|
call.reject(message ?? "")
|
|
47
47
|
} else {
|
|
@@ -50,7 +50,7 @@ public class AudioSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
50
50
|
"message": message ?? ""
|
|
51
51
|
])
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
})
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-audio-session",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "This capacitor plugin allows iOS applications to get notified audio about interrupts & route changes (for example when a headset is connected), and also query and override the audio device in use.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|