@capawesome/capacitor-audio-session 0.0.1
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/CapawesomeCapacitorAudioSession.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +389 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/audiosession/AudioSessionPlugin.java +35 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +759 -0
- package/dist/esm/definitions.d.ts +287 -0
- package/dist/esm/definitions.js +19 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +49 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +52 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AudioSession.swift +127 -0
- package/ios/Plugin/AudioSessionPlugin.swift +103 -0
- package/ios/Plugin/Classes/Events/InterruptionEvent.swift +19 -0
- package/ios/Plugin/Classes/Events/RouteChangeEvent.swift +19 -0
- package/ios/Plugin/Classes/Options/ConfigureOptions.swift +101 -0
- package/ios/Plugin/Classes/Options/OverrideOutputOptions.swift +24 -0
- package/ios/Plugin/Classes/Options/SetActiveOptions.swift +27 -0
- package/ios/Plugin/Classes/Results/AudioSessionOutput.swift +19 -0
- package/ios/Plugin/Classes/Results/GetCurrentOutputsResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +36 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorAudioSession'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorAudioSession",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorAudioSession",
|
|
10
|
+
targets: ["AudioSessionPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "AudioSessionPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "AudioSessionPluginTests",
|
|
25
|
+
dependencies: ["AudioSessionPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
# @capawesome/capacitor-audio-session
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to configure and observe the iOS [audio session](https://developer.apple.com/documentation/avfaudio/avaudiosession).
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
We are proud to offer one of the most complete and feature-rich Capacitor plugins for the iOS audio session. Here are some of the key features:
|
|
14
|
+
|
|
15
|
+
- 🎛️ **Configuration**: Set the audio session category, mode and options.
|
|
16
|
+
- 🔌 **Activation**: Activate and deactivate the audio session.
|
|
17
|
+
- 🔊 **Output routing**: Read the current audio outputs and override the output port.
|
|
18
|
+
- 📡 **Events**: Observe interruption and route change events.
|
|
19
|
+
- 🔗 **Compatibility**: Works alongside the [Audio Player](https://capawesome.io/plugins/audio-player/) and [Audio Recorder](https://capawesome.io/plugins/audio-recorder/) plugins.
|
|
20
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
21
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
22
|
+
|
|
23
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
24
|
+
|
|
25
|
+
## Newsletter
|
|
26
|
+
|
|
27
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
28
|
+
|
|
29
|
+
## Compatibility
|
|
30
|
+
|
|
31
|
+
| Plugin Version | Capacitor Version | Status |
|
|
32
|
+
| -------------- | ----------------- | -------------- |
|
|
33
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
38
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then use the following prompt:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-audio-session` plugin in my project.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @capawesome/capacitor-audio-session
|
|
54
|
+
npx cap sync
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This plugin is only available on **iOS**. On Android and Web, all methods reject as unimplemented.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
No configuration required for this plugin.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { AudioSession } from '@capawesome/capacitor-audio-session';
|
|
67
|
+
|
|
68
|
+
const configure = async () => {
|
|
69
|
+
await AudioSession.configure({
|
|
70
|
+
category: 'playback',
|
|
71
|
+
mode: 'moviePlayback',
|
|
72
|
+
options: {
|
|
73
|
+
mixWithOthers: false,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const setActive = async () => {
|
|
79
|
+
await AudioSession.setActive({ active: true });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const getCurrentOutputs = async () => {
|
|
83
|
+
const { outputs } = await AudioSession.getCurrentOutputs();
|
|
84
|
+
return outputs;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const overrideOutput = async () => {
|
|
88
|
+
await AudioSession.overrideOutput({ type: 'speaker' });
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const addInterruptionListener = async () => {
|
|
92
|
+
await AudioSession.addListener('interruption', event => {
|
|
93
|
+
console.log('Interruption:', event.type, event.shouldResume);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const addRouteChangeListener = async () => {
|
|
98
|
+
await AudioSession.addListener('routeChange', event => {
|
|
99
|
+
console.log('Route change:', event.reason, event.outputs);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const removeAllListeners = async () => {
|
|
104
|
+
await AudioSession.removeAllListeners();
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## API
|
|
109
|
+
|
|
110
|
+
<docgen-index>
|
|
111
|
+
|
|
112
|
+
* [`addListener('interruption', ...)`](#addlistenerinterruption-)
|
|
113
|
+
* [`addListener('routeChange', ...)`](#addlistenerroutechange-)
|
|
114
|
+
* [`configure(...)`](#configure)
|
|
115
|
+
* [`getCurrentOutputs()`](#getcurrentoutputs)
|
|
116
|
+
* [`overrideOutput(...)`](#overrideoutput)
|
|
117
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
118
|
+
* [`setActive(...)`](#setactive)
|
|
119
|
+
* [Interfaces](#interfaces)
|
|
120
|
+
* [Type Aliases](#type-aliases)
|
|
121
|
+
|
|
122
|
+
</docgen-index>
|
|
123
|
+
|
|
124
|
+
<docgen-api>
|
|
125
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
126
|
+
|
|
127
|
+
### addListener('interruption', ...)
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
addListener(eventName: 'interruption', listenerFunc: (event: InterruptionEvent) => void) => Promise<PluginListenerHandle>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Called when the audio session is interrupted, e.g. by an incoming phone call.
|
|
134
|
+
|
|
135
|
+
Only available on iOS.
|
|
136
|
+
|
|
137
|
+
| Param | Type |
|
|
138
|
+
| ------------------ | ----------------------------------------------------------------------------------- |
|
|
139
|
+
| **`eventName`** | <code>'interruption'</code> |
|
|
140
|
+
| **`listenerFunc`** | <code>(event: <a href="#interruptionevent">InterruptionEvent</a>) => void</code> |
|
|
141
|
+
|
|
142
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
143
|
+
|
|
144
|
+
**Since:** 0.1.0
|
|
145
|
+
|
|
146
|
+
--------------------
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
### addListener('routeChange', ...)
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
addListener(eventName: 'routeChange', listenerFunc: (event: RouteChangeEvent) => void) => Promise<PluginListenerHandle>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Called when the audio route changes, e.g. when headphones are plugged in or out.
|
|
156
|
+
|
|
157
|
+
Only available on iOS.
|
|
158
|
+
|
|
159
|
+
| Param | Type |
|
|
160
|
+
| ------------------ | --------------------------------------------------------------------------------- |
|
|
161
|
+
| **`eventName`** | <code>'routeChange'</code> |
|
|
162
|
+
| **`listenerFunc`** | <code>(event: <a href="#routechangeevent">RouteChangeEvent</a>) => void</code> |
|
|
163
|
+
|
|
164
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
165
|
+
|
|
166
|
+
**Since:** 0.1.0
|
|
167
|
+
|
|
168
|
+
--------------------
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### configure(...)
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
configure(options: ConfigureOptions) => Promise<void>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Configure the audio session category, mode and options.
|
|
178
|
+
|
|
179
|
+
Only available on iOS.
|
|
180
|
+
|
|
181
|
+
| Param | Type |
|
|
182
|
+
| ------------- | ------------------------------------------------------------- |
|
|
183
|
+
| **`options`** | <code><a href="#configureoptions">ConfigureOptions</a></code> |
|
|
184
|
+
|
|
185
|
+
**Since:** 0.1.0
|
|
186
|
+
|
|
187
|
+
--------------------
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
### getCurrentOutputs()
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
getCurrentOutputs() => Promise<GetCurrentOutputsResult>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Get the audio outputs of the current audio route.
|
|
197
|
+
|
|
198
|
+
Only available on iOS.
|
|
199
|
+
|
|
200
|
+
**Returns:** <code>Promise<<a href="#getcurrentoutputsresult">GetCurrentOutputsResult</a>></code>
|
|
201
|
+
|
|
202
|
+
**Since:** 0.1.0
|
|
203
|
+
|
|
204
|
+
--------------------
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
### overrideOutput(...)
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
overrideOutput(options: OverrideOutputOptions) => Promise<void>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Override the audio output port that is used for playback.
|
|
214
|
+
|
|
215
|
+
Only available on iOS.
|
|
216
|
+
|
|
217
|
+
| Param | Type |
|
|
218
|
+
| ------------- | ----------------------------------------------------------------------- |
|
|
219
|
+
| **`options`** | <code><a href="#overrideoutputoptions">OverrideOutputOptions</a></code> |
|
|
220
|
+
|
|
221
|
+
**Since:** 0.1.0
|
|
222
|
+
|
|
223
|
+
--------------------
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### removeAllListeners()
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
removeAllListeners() => Promise<void>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Remove all listeners for this plugin.
|
|
233
|
+
|
|
234
|
+
Only available on iOS.
|
|
235
|
+
|
|
236
|
+
**Since:** 0.1.0
|
|
237
|
+
|
|
238
|
+
--------------------
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### setActive(...)
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
setActive(options: SetActiveOptions) => Promise<void>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Activate or deactivate the audio session.
|
|
248
|
+
|
|
249
|
+
Only available on iOS.
|
|
250
|
+
|
|
251
|
+
| Param | Type |
|
|
252
|
+
| ------------- | ------------------------------------------------------------- |
|
|
253
|
+
| **`options`** | <code><a href="#setactiveoptions">SetActiveOptions</a></code> |
|
|
254
|
+
|
|
255
|
+
**Since:** 0.1.0
|
|
256
|
+
|
|
257
|
+
--------------------
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
### Interfaces
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
#### PluginListenerHandle
|
|
264
|
+
|
|
265
|
+
| Prop | Type |
|
|
266
|
+
| ------------ | ----------------------------------------- |
|
|
267
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
#### InterruptionEvent
|
|
271
|
+
|
|
272
|
+
| Prop | Type | Description | Since |
|
|
273
|
+
| ------------------ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ----- |
|
|
274
|
+
| **`shouldResume`** | <code>boolean</code> | Whether playback should resume after the interruption ended. Only `true` if `type` is `ended`. | 0.1.0 |
|
|
275
|
+
| **`type`** | <code><a href="#interruptiontype">InterruptionType</a></code> | The type of the interruption. | 0.1.0 |
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
#### RouteChangeEvent
|
|
279
|
+
|
|
280
|
+
| Prop | Type | Description | Since |
|
|
281
|
+
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------ | ----- |
|
|
282
|
+
| **`outputs`** | <code>AudioSessionOutput[]</code> | The audio outputs of the audio route after the change. | 0.1.0 |
|
|
283
|
+
| **`reason`** | <code><a href="#routechangereason">RouteChangeReason</a></code> | The reason why the audio route changed. | 0.1.0 |
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
#### AudioSessionOutput
|
|
287
|
+
|
|
288
|
+
| Prop | Type | Description | Since |
|
|
289
|
+
| -------------- | ------------------- | ------------------------------------------------- | ----- |
|
|
290
|
+
| **`portName`** | <code>string</code> | The human-readable name of the audio output port. | 0.1.0 |
|
|
291
|
+
| **`portType`** | <code>string</code> | The type of the audio output port. | 0.1.0 |
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
#### ConfigureOptions
|
|
295
|
+
|
|
296
|
+
| Prop | Type | Description | Default | Since |
|
|
297
|
+
| -------------- | ----------------------------------------------------------------------------------- | ----------------------------------- | ---------------------- | ----- |
|
|
298
|
+
| **`category`** | <code><a href="#audiosessioncategory">AudioSessionCategory</a></code> | The audio session category. | | 0.1.0 |
|
|
299
|
+
| **`mode`** | <code><a href="#audiosessionmode">AudioSessionMode</a></code> | The audio session mode. | <code>'default'</code> | 0.1.0 |
|
|
300
|
+
| **`options`** | <code><a href="#audiosessioncategoryoptions">AudioSessionCategoryOptions</a></code> | The audio session category options. | | 0.1.0 |
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
#### AudioSessionCategoryOptions
|
|
304
|
+
|
|
305
|
+
| Prop | Type | Description | Default | Since |
|
|
306
|
+
| ------------------------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
|
|
307
|
+
| **`allowAirPlay`** | <code>boolean</code> | Whether AirPlay devices can be used for output. | <code>false</code> | 0.1.0 |
|
|
308
|
+
| **`allowBluetooth`** | <code>boolean</code> | Whether Bluetooth hands-free devices can be used for input and output. | <code>false</code> | 0.1.0 |
|
|
309
|
+
| **`allowBluetoothA2DP`** | <code>boolean</code> | Whether Bluetooth A2DP devices can be used for output. | <code>false</code> | 0.1.0 |
|
|
310
|
+
| **`defaultToSpeaker`** | <code>boolean</code> | Whether audio is routed to the built-in speaker instead of the receiver when no other audio route is connected. | <code>false</code> | 0.1.0 |
|
|
311
|
+
| **`duckOthers`** | <code>boolean</code> | Whether audio from other sessions is reduced in volume (ducked) while audio from this session plays. | <code>false</code> | 0.1.0 |
|
|
312
|
+
| **`interruptSpokenAudioAndMixWithOthers`** | <code>boolean</code> | Whether audio from other sessions using the `spokenAudio` mode is interrupted and audio from this session is mixed with the remaining audio. | <code>false</code> | 0.1.0 |
|
|
313
|
+
| **`mixWithOthers`** | <code>boolean</code> | Whether audio from this session mixes with audio from other active sessions instead of interrupting them. | <code>false</code> | 0.1.0 |
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
#### GetCurrentOutputsResult
|
|
317
|
+
|
|
318
|
+
| Prop | Type | Description | Since |
|
|
319
|
+
| ------------- | --------------------------------- | --------------------------------------------- | ----- |
|
|
320
|
+
| **`outputs`** | <code>AudioSessionOutput[]</code> | The audio outputs of the current audio route. | 0.1.0 |
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
#### OverrideOutputOptions
|
|
324
|
+
|
|
325
|
+
| Prop | Type | Description | Since |
|
|
326
|
+
| ---------- | ----------------------------------------------------------------- | ------------------------------------------- | ----- |
|
|
327
|
+
| **`type`** | <code><a href="#overrideoutputtype">OverrideOutputType</a></code> | The audio output port to route playback to. | 0.1.0 |
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
#### SetActiveOptions
|
|
331
|
+
|
|
332
|
+
| Prop | Type | Description | Default | Since |
|
|
333
|
+
| -------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------- | ----------------- | ----- |
|
|
334
|
+
| **`active`** | <code>boolean</code> | Whether the audio session should be activated (`true`) or deactivated (`false`). | | 0.1.0 |
|
|
335
|
+
| **`notifyOthersOnDeactivation`** | <code>boolean</code> | Whether other audio sessions are notified when this session is deactivated, so they can resume playback. | <code>true</code> | 0.1.0 |
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
### Type Aliases
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
#### InterruptionType
|
|
342
|
+
|
|
343
|
+
The type of an audio session interruption.
|
|
344
|
+
|
|
345
|
+
<code>'began' | 'ended'</code>
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
#### RouteChangeReason
|
|
349
|
+
|
|
350
|
+
The reason why the audio route changed.
|
|
351
|
+
|
|
352
|
+
<code>'categoryChange' | 'newDeviceAvailable' | 'noSuitableRouteForCategory' | 'oldDeviceUnavailable' | 'override' | 'routeConfigurationChange' | 'unknown' | 'wakeFromSleep'</code>
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
#### AudioSessionCategory
|
|
356
|
+
|
|
357
|
+
The audio session category.
|
|
358
|
+
|
|
359
|
+
<code>'ambient' | 'multiRoute' | 'playAndRecord' | 'playback' | 'record' | 'soloAmbient'</code>
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
#### AudioSessionMode
|
|
363
|
+
|
|
364
|
+
The audio session mode.
|
|
365
|
+
|
|
366
|
+
<code>'default' | 'gameChat' | 'measurement' | 'moviePlayback' | 'spokenAudio' | 'videoChat' | 'videoRecording' | 'voiceChat' | 'voicePrompt'</code>
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
#### OverrideOutputType
|
|
370
|
+
|
|
371
|
+
The audio output port to route playback to.
|
|
372
|
+
|
|
373
|
+
<code>'default' | 'speaker'</code>
|
|
374
|
+
|
|
375
|
+
</docgen-api>
|
|
376
|
+
|
|
377
|
+
## Session Ownership
|
|
378
|
+
|
|
379
|
+
The audio session returned by [`AVAudioSession.sharedInstance()`](https://developer.apple.com/documentation/avfaudio/avaudiosession) is a **single, app-wide** object. This plugin gives you **manual** control over it, but so do other audio-related plugins (such as the [Audio Player](https://capawesome.io/plugins/audio-player/), [Audio Recorder](https://capawesome.io/plugins/audio-recorder/) and Speech Recognition plugins) and the underlying platform APIs they use.
|
|
380
|
+
|
|
381
|
+
Because the session is shared, the **last write wins**: calling `configure(...)` may override the category, mode or options that another plugin has set, and vice versa. This plugin cannot prevent that. If you combine this plugin with other audio plugins, make sure to reconfigure the session whenever you switch between playback, recording and other audio scenarios.
|
|
382
|
+
|
|
383
|
+
## Changelog
|
|
384
|
+
|
|
385
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/audio-session/CHANGELOG.md).
|
|
386
|
+
|
|
387
|
+
## License
|
|
388
|
+
|
|
389
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/audio-session/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.audiosession"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/audiosession/AudioSessionPlugin.java
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.audiosession;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.Plugin;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.getcapacitor.PluginMethod;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
|
|
9
|
+
@CapacitorPlugin(name = "AudioSession")
|
|
10
|
+
public class AudioSessionPlugin extends Plugin {
|
|
11
|
+
|
|
12
|
+
@PluginMethod
|
|
13
|
+
public void configure(PluginCall call) {
|
|
14
|
+
rejectCallAsUnimplemented(call);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@PluginMethod
|
|
18
|
+
public void getCurrentOutputs(PluginCall call) {
|
|
19
|
+
rejectCallAsUnimplemented(call);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@PluginMethod
|
|
23
|
+
public void overrideOutput(PluginCall call) {
|
|
24
|
+
rejectCallAsUnimplemented(call);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PluginMethod
|
|
28
|
+
public void setActive(PluginCall call) {
|
|
29
|
+
rejectCallAsUnimplemented(call);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private void rejectCallAsUnimplemented(@NonNull PluginCall call) {
|
|
33
|
+
call.unimplemented("This method is not available on this platform.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
File without changes
|