@capawesome/capacitor-volume 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/CapawesomeCapacitorVolume.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +405 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/Volume.java +158 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/VolumeHelper.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/VolumePlugin.java +178 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/CustomExceptions.java +12 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/events/VolumeButtonPressedEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/events/VolumeChangeEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/GetVolumeOptions.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/SetVolumeOptions.java +41 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/StartWatchingOptions.java +17 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/results/GetVolumeResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/results/IsWatchingResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +540 -0
- package/dist/esm/definitions.d.ts +255 -0
- package/dist/esm/definitions.js +60 -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 +9 -0
- package/dist/esm/web.js +19 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +93 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +96 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Events/VolumeButtonPressedEvent.swift +16 -0
- package/ios/Plugin/Classes/Events/VolumeChangeEvent.swift +16 -0
- package/ios/Plugin/Classes/Options/SetVolumeOptions.swift +20 -0
- package/ios/Plugin/Classes/Options/StartWatchingOptions.swift +10 -0
- package/ios/Plugin/Classes/Results/GetVolumeResult.swift +16 -0
- package/ios/Plugin/Classes/Results/IsWatchingResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +24 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/ios/Plugin/Volume.swift +192 -0
- package/ios/Plugin/VolumePlugin.swift +109 -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 = 'CapawesomeCapacitorVolume'
|
|
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: "CapawesomeCapacitorVolume",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorVolume",
|
|
10
|
+
targets: ["VolumePlugin"])
|
|
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: "VolumePlugin",
|
|
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: "VolumePluginTests",
|
|
25
|
+
dependencies: ["VolumePlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# @capawesome/capacitor-volume
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to control the volume and observe hardware volume button presses.
|
|
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
|
+
- 🔊 **Volume control**: Get and set the volume level.
|
|
14
|
+
- 🎚️ **Audio streams**: Control individual audio streams (music, ring, alarm and more) on Android.
|
|
15
|
+
- 🔘 **Volume buttons**: Listen for hardware volume button presses.
|
|
16
|
+
- 🤫 **Suppression**: Keep the volume unchanged and hide the system volume indicator while watching.
|
|
17
|
+
- 👂 **Change events**: Listen for changes to the volume level.
|
|
18
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
19
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
20
|
+
|
|
21
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
|
+
|
|
23
|
+
## Newsletter
|
|
24
|
+
|
|
25
|
+
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/).
|
|
26
|
+
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
29
|
+
| Plugin Version | Capacitor Version | Status |
|
|
30
|
+
| -------------- | ----------------- | -------------- |
|
|
31
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
36
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then use the following prompt:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-volume` plugin in my project.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @capawesome/capacitor-volume
|
|
52
|
+
npx cap sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This plugin is only available on **Android** and **iOS**. On the Web, all methods reject as unimplemented.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
No configuration required for this plugin.
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { Volume, VolumeStream } from '@capawesome/capacitor-volume';
|
|
65
|
+
|
|
66
|
+
const getVolume = async () => {
|
|
67
|
+
const { volume } = await Volume.getVolume();
|
|
68
|
+
return volume;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getRingVolume = async () => {
|
|
72
|
+
const { volume } = await Volume.getVolume({ stream: VolumeStream.Ring });
|
|
73
|
+
return volume;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const setVolume = async () => {
|
|
77
|
+
await Volume.setVolume({ volume: 0.5 });
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const startWatching = async () => {
|
|
81
|
+
await Volume.startWatching({ suppressVolumeChange: true });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const stopWatching = async () => {
|
|
85
|
+
await Volume.stopWatching();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const isWatching = async () => {
|
|
89
|
+
const { watching } = await Volume.isWatching();
|
|
90
|
+
return watching;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const addVolumeButtonPressedListener = async () => {
|
|
94
|
+
await Volume.addListener('volumeButtonPressed', event => {
|
|
95
|
+
console.log('Volume button pressed:', event.direction);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const addVolumeChangeListener = async () => {
|
|
100
|
+
await Volume.addListener('volumeChange', event => {
|
|
101
|
+
console.log('Volume changed:', event.volume);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const removeAllListeners = async () => {
|
|
106
|
+
await Volume.removeAllListeners();
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## API
|
|
111
|
+
|
|
112
|
+
<docgen-index>
|
|
113
|
+
|
|
114
|
+
* [`getVolume(...)`](#getvolume)
|
|
115
|
+
* [`isWatching()`](#iswatching)
|
|
116
|
+
* [`setVolume(...)`](#setvolume)
|
|
117
|
+
* [`startWatching(...)`](#startwatching)
|
|
118
|
+
* [`stopWatching()`](#stopwatching)
|
|
119
|
+
* [`addListener('volumeButtonPressed', ...)`](#addlistenervolumebuttonpressed-)
|
|
120
|
+
* [`addListener('volumeChange', ...)`](#addlistenervolumechange-)
|
|
121
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
122
|
+
* [Interfaces](#interfaces)
|
|
123
|
+
* [Type Aliases](#type-aliases)
|
|
124
|
+
* [Enums](#enums)
|
|
125
|
+
|
|
126
|
+
</docgen-index>
|
|
127
|
+
|
|
128
|
+
<docgen-api>
|
|
129
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
130
|
+
|
|
131
|
+
### getVolume(...)
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
getVolume(options?: GetVolumeOptions | undefined) => Promise<GetVolumeResult>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Get the current volume level.
|
|
138
|
+
|
|
139
|
+
On iOS, this always returns the media volume.
|
|
140
|
+
|
|
141
|
+
Only available on Android and iOS.
|
|
142
|
+
|
|
143
|
+
| Param | Type |
|
|
144
|
+
| ------------- | ------------------------------------------------------------- |
|
|
145
|
+
| **`options`** | <code><a href="#getvolumeoptions">GetVolumeOptions</a></code> |
|
|
146
|
+
|
|
147
|
+
**Returns:** <code>Promise<<a href="#getvolumeresult">GetVolumeResult</a>></code>
|
|
148
|
+
|
|
149
|
+
**Since:** 0.1.0
|
|
150
|
+
|
|
151
|
+
--------------------
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### isWatching()
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
isWatching() => Promise<IsWatchingResult>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Check whether the hardware volume buttons are currently being watched.
|
|
161
|
+
|
|
162
|
+
Only available on Android and iOS.
|
|
163
|
+
|
|
164
|
+
**Returns:** <code>Promise<<a href="#iswatchingresult">IsWatchingResult</a>></code>
|
|
165
|
+
|
|
166
|
+
**Since:** 0.1.0
|
|
167
|
+
|
|
168
|
+
--------------------
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### setVolume(...)
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
setVolume(options: SetVolumeOptions) => Promise<void>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Set the volume level.
|
|
178
|
+
|
|
179
|
+
On iOS, this always sets the media volume.
|
|
180
|
+
|
|
181
|
+
Only available on Android and iOS.
|
|
182
|
+
|
|
183
|
+
| Param | Type |
|
|
184
|
+
| ------------- | ------------------------------------------------------------- |
|
|
185
|
+
| **`options`** | <code><a href="#setvolumeoptions">SetVolumeOptions</a></code> |
|
|
186
|
+
|
|
187
|
+
**Since:** 0.1.0
|
|
188
|
+
|
|
189
|
+
--------------------
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### startWatching(...)
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
startWatching(options?: StartWatchingOptions | undefined) => Promise<void>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Start watching the hardware volume buttons.
|
|
199
|
+
|
|
200
|
+
The `volumeButtonPressed` and `volumeChange` events are only
|
|
201
|
+
emitted while watching.
|
|
202
|
+
|
|
203
|
+
If the volume buttons are already being watched, this call has
|
|
204
|
+
no effect. Call `stopWatching()` first to change the options.
|
|
205
|
+
|
|
206
|
+
Only available on Android and iOS.
|
|
207
|
+
|
|
208
|
+
| Param | Type |
|
|
209
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
210
|
+
| **`options`** | <code><a href="#startwatchingoptions">StartWatchingOptions</a></code> |
|
|
211
|
+
|
|
212
|
+
**Since:** 0.1.0
|
|
213
|
+
|
|
214
|
+
--------------------
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
### stopWatching()
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
stopWatching() => Promise<void>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Stop watching the hardware volume buttons.
|
|
224
|
+
|
|
225
|
+
On iOS, this also restores the volume level that was set when
|
|
226
|
+
watching started if the `suppressVolumeChange` option was enabled.
|
|
227
|
+
|
|
228
|
+
Only available on Android and iOS.
|
|
229
|
+
|
|
230
|
+
**Since:** 0.1.0
|
|
231
|
+
|
|
232
|
+
--------------------
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
### addListener('volumeButtonPressed', ...)
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
addListener(eventName: 'volumeButtonPressed', listenerFunc: (event: VolumeButtonPressedEvent) => void) => Promise<PluginListenerHandle>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Called when a hardware volume button is pressed while watching.
|
|
242
|
+
|
|
243
|
+
Only available on Android and iOS.
|
|
244
|
+
|
|
245
|
+
| Param | Type |
|
|
246
|
+
| ------------------ | ------------------------------------------------------------------------------------------------- |
|
|
247
|
+
| **`eventName`** | <code>'volumeButtonPressed'</code> |
|
|
248
|
+
| **`listenerFunc`** | <code>(event: <a href="#volumebuttonpressedevent">VolumeButtonPressedEvent</a>) => void</code> |
|
|
249
|
+
|
|
250
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
251
|
+
|
|
252
|
+
**Since:** 0.1.0
|
|
253
|
+
|
|
254
|
+
--------------------
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
### addListener('volumeChange', ...)
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
addListener(eventName: 'volumeChange', listenerFunc: (event: VolumeChangeEvent) => void) => Promise<PluginListenerHandle>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Called when the volume level changes while watching.
|
|
264
|
+
|
|
265
|
+
On Android, this is called for changes to the music stream.
|
|
266
|
+
On iOS, this is called for changes to the media volume and is
|
|
267
|
+
not called while the `suppressVolumeChange` option is enabled.
|
|
268
|
+
|
|
269
|
+
Only available on Android and iOS.
|
|
270
|
+
|
|
271
|
+
| Param | Type |
|
|
272
|
+
| ------------------ | ----------------------------------------------------------------------------------- |
|
|
273
|
+
| **`eventName`** | <code>'volumeChange'</code> |
|
|
274
|
+
| **`listenerFunc`** | <code>(event: <a href="#volumechangeevent">VolumeChangeEvent</a>) => void</code> |
|
|
275
|
+
|
|
276
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
277
|
+
|
|
278
|
+
**Since:** 0.1.0
|
|
279
|
+
|
|
280
|
+
--------------------
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
### removeAllListeners()
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
removeAllListeners() => Promise<void>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Remove all listeners for this plugin.
|
|
290
|
+
|
|
291
|
+
**Since:** 0.1.0
|
|
292
|
+
|
|
293
|
+
--------------------
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
### Interfaces
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
#### GetVolumeResult
|
|
300
|
+
|
|
301
|
+
| Prop | Type | Description | Since |
|
|
302
|
+
| ------------ | ------------------- | -------------------------------------------------------- | ----- |
|
|
303
|
+
| **`volume`** | <code>number</code> | The current volume level as a value between `0` and `1`. | 0.1.0 |
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
#### GetVolumeOptions
|
|
307
|
+
|
|
308
|
+
| Prop | Type | Description | Default | Since |
|
|
309
|
+
| ------------ | ----------------------------------------------------- | ------------------------------------------------------------------ | ------------------------------- | ----- |
|
|
310
|
+
| **`stream`** | <code><a href="#volumestream">VolumeStream</a></code> | The audio stream to get the volume for. Only available on Android. | <code>VolumeStream.Music</code> | 0.1.0 |
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
#### IsWatchingResult
|
|
314
|
+
|
|
315
|
+
| Prop | Type | Description | Since |
|
|
316
|
+
| -------------- | -------------------- | ---------------------------------------------------------------- | ----- |
|
|
317
|
+
| **`watching`** | <code>boolean</code> | Whether the hardware volume buttons are currently being watched. | 0.1.0 |
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
#### SetVolumeOptions
|
|
321
|
+
|
|
322
|
+
| Prop | Type | Description | Default | Since |
|
|
323
|
+
| ------------ | ----------------------------------------------------- | ------------------------------------------------------------------ | ------------------------------- | ----- |
|
|
324
|
+
| **`stream`** | <code><a href="#volumestream">VolumeStream</a></code> | The audio stream to set the volume for. Only available on Android. | <code>VolumeStream.Music</code> | 0.1.0 |
|
|
325
|
+
| **`volume`** | <code>number</code> | The volume level to set as a value between `0` and `1`. | | 0.1.0 |
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
#### StartWatchingOptions
|
|
329
|
+
|
|
330
|
+
| Prop | Type | Description | Default | Since |
|
|
331
|
+
| -------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
|
|
332
|
+
| **`suppressVolumeChange`** | <code>boolean</code> | Whether to keep the volume level unchanged when a hardware volume button is pressed while watching. On Android, the volume key events are consumed so that the system does not apply the volume change or display the volume panel. On iOS, the volume level is reset immediately after each button press and the system volume indicator is hidden. If the volume level is close to the minimum or maximum, it is nudged to a value from which both buttons can still be detected. The original volume level is restored when watching stops. | <code>false</code> | 0.1.0 |
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
#### PluginListenerHandle
|
|
336
|
+
|
|
337
|
+
| Prop | Type |
|
|
338
|
+
| ------------ | ----------------------------------------- |
|
|
339
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
#### VolumeButtonPressedEvent
|
|
343
|
+
|
|
344
|
+
| Prop | Type | Description | Since |
|
|
345
|
+
| --------------- | ----------------------------------------------- | ---------------------------------------------------- | ----- |
|
|
346
|
+
| **`direction`** | <code><a href="#direction">Direction</a></code> | The direction of the pressed hardware volume button. | 0.1.0 |
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
#### VolumeChangeEvent
|
|
350
|
+
|
|
351
|
+
| Prop | Type | Description | Since |
|
|
352
|
+
| ------------ | ------------------- | ---------------------------------------------------- | ----- |
|
|
353
|
+
| **`volume`** | <code>number</code> | The new volume level as a value between `0` and `1`. | 0.1.0 |
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
### Type Aliases
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
#### Direction
|
|
360
|
+
|
|
361
|
+
The direction of a hardware volume button.
|
|
362
|
+
|
|
363
|
+
- `up`: The volume up button.
|
|
364
|
+
- `down`: The volume down button.
|
|
365
|
+
|
|
366
|
+
<code>'down' | 'up'</code>
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
### Enums
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
#### VolumeStream
|
|
373
|
+
|
|
374
|
+
| Members | Value | Description | Since |
|
|
375
|
+
| ------------------ | --------------------------- | ---------------------------------------------- | ----- |
|
|
376
|
+
| **`Alarm`** | <code>'alarm'</code> | The audio stream for alarms. | 0.1.0 |
|
|
377
|
+
| **`Music`** | <code>'music'</code> | The audio stream for music and media playback. | 0.1.0 |
|
|
378
|
+
| **`Notification`** | <code>'notification'</code> | The audio stream for notifications. | 0.1.0 |
|
|
379
|
+
| **`Ring`** | <code>'ring'</code> | The audio stream for the phone ring. | 0.1.0 |
|
|
380
|
+
| **`System`** | <code>'system'</code> | The audio stream for system sounds. | 0.1.0 |
|
|
381
|
+
| **`VoiceCall`** | <code>'voiceCall'</code> | The audio stream for phone calls. | 0.1.0 |
|
|
382
|
+
|
|
383
|
+
</docgen-api>
|
|
384
|
+
|
|
385
|
+
## Volume Control
|
|
386
|
+
|
|
387
|
+
Keep the following platform differences in mind when getting and setting the volume:
|
|
388
|
+
|
|
389
|
+
- **Android**: The volume can be read and set per audio stream (see the `stream` option). If Do Not Disturb is active, changing the volume of the ring, notification or system stream requires Do Not Disturb access. Without this access, the call is rejected with the `DO_NOT_DISTURB_ACCESS_REQUIRED` error code. You can direct the user to the corresponding settings screen using the [`ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS`](https://developer.android.com/reference/android/provider/Settings#ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS) intent, for example with the [App Launcher](https://capacitorjs.com/docs/apis/app-launcher) plugin.
|
|
390
|
+
- **iOS**: There is no public API to set the system volume directly. The plugin therefore uses a hidden system volume view to change the media volume, which is the only volume that can be read and set. The `stream` option is ignored.
|
|
391
|
+
|
|
392
|
+
## Volume Button Watching
|
|
393
|
+
|
|
394
|
+
Keep the following platform differences in mind when watching the hardware volume buttons:
|
|
395
|
+
|
|
396
|
+
- **Android**: The volume key events are intercepted by the web view, so button presses are only detected while the app is in the foreground. With the `suppressVolumeChange` option enabled, the key events are consumed, which keeps the volume unchanged and prevents the system volume panel from appearing.
|
|
397
|
+
- **iOS**: Button presses are derived from changes to the media volume, so button presses are only detected while the app is in the foreground. Without the `suppressVolumeChange` option, presses can not be detected once the volume has reached its minimum or maximum. With the option enabled, the volume is reset immediately after each press (nudged away from the edges if needed), the system volume indicator is hidden, and the original volume is restored when watching stops. Note that volume changes from other sources (for example Control Center) are also reported while watching.
|
|
398
|
+
|
|
399
|
+
## Changelog
|
|
400
|
+
|
|
401
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/volume/CHANGELOG.md).
|
|
402
|
+
|
|
403
|
+
## License
|
|
404
|
+
|
|
405
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/volume/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.volume"
|
|
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
|
+
}
|