@capawesome/capacitor-volume 0.0.1 → 0.1.0
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/README.md +100 -9
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/VolumeHelper.java +6 -6
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/GetVolumeOptions.java +1 -1
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/SetVolumeOptions.java +1 -1
- package/dist/docs.json +8 -8
- package/dist/esm/definitions.d.ts +8 -8
- package/dist/esm/definitions.js +6 -6
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +6 -6
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -6
- package/dist/plugin.js.map +1 -1
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Capacitor Volume Plugin
|
|
2
2
|
|
|
3
3
|
Capacitor plugin to control the volume and observe hardware volume button presses.
|
|
4
4
|
|
|
@@ -20,9 +20,14 @@ Capacitor plugin to control the volume and observe hardware volume button presse
|
|
|
20
20
|
|
|
21
21
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Use Cases
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The Volume plugin is typically used whenever an app needs to control the volume or react to the hardware volume buttons, for example:
|
|
26
|
+
|
|
27
|
+
- **Media apps**: Read and adjust the media volume from your own player UI.
|
|
28
|
+
- **Camera apps**: Use the hardware volume buttons as a shutter trigger while keeping the volume unchanged.
|
|
29
|
+
- **Remote control apps**: Map the volume buttons to custom actions, for example to control external devices.
|
|
30
|
+
- **Audio guidance**: Warn users when the volume is too low to hear important audio cues.
|
|
26
31
|
|
|
27
32
|
## Compatibility
|
|
28
33
|
|
|
@@ -60,6 +65,12 @@ No configuration required for this plugin.
|
|
|
60
65
|
|
|
61
66
|
## Usage
|
|
62
67
|
|
|
68
|
+
The following examples show how to get and set the current volume, watch the hardware volume buttons, listen for volume button presses and volume changes, and remove all listeners.
|
|
69
|
+
|
|
70
|
+
### Get the current volume
|
|
71
|
+
|
|
72
|
+
Read the current volume level as a value between `0` and `1`. On Android, you can select the audio stream (for example the ring stream) with the `stream` option. On iOS, this always returns the media volume:
|
|
73
|
+
|
|
63
74
|
```typescript
|
|
64
75
|
import { Volume, VolumeStream } from '@capawesome/capacitor-volume';
|
|
65
76
|
|
|
@@ -72,10 +83,26 @@ const getRingVolume = async () => {
|
|
|
72
83
|
const { volume } = await Volume.getVolume({ stream: VolumeStream.Ring });
|
|
73
84
|
return volume;
|
|
74
85
|
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Set the volume
|
|
89
|
+
|
|
90
|
+
Set the volume level as a value between `0` and `1`. On Android, you can select the audio stream with the `stream` option. On iOS, this always sets the media volume:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { Volume } from '@capawesome/capacitor-volume';
|
|
75
94
|
|
|
76
95
|
const setVolume = async () => {
|
|
77
96
|
await Volume.setVolume({ volume: 0.5 });
|
|
78
97
|
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Watch the hardware volume buttons
|
|
101
|
+
|
|
102
|
+
Start watching the hardware volume buttons to receive the `volumeButtonPressed` and `volumeChange` events. With the `suppressVolumeChange` option enabled, the volume level is kept unchanged and the system volume indicator is hidden while watching:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { Volume } from '@capawesome/capacitor-volume';
|
|
79
106
|
|
|
80
107
|
const startWatching = async () => {
|
|
81
108
|
await Volume.startWatching({ suppressVolumeChange: true });
|
|
@@ -89,18 +116,42 @@ const isWatching = async () => {
|
|
|
89
116
|
const { watching } = await Volume.isWatching();
|
|
90
117
|
return watching;
|
|
91
118
|
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Listen for volume button presses
|
|
122
|
+
|
|
123
|
+
Get notified when a hardware volume button is pressed. The event is only emitted while watching (see above):
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { Volume } from '@capawesome/capacitor-volume';
|
|
92
127
|
|
|
93
128
|
const addVolumeButtonPressedListener = async () => {
|
|
94
129
|
await Volume.addListener('volumeButtonPressed', event => {
|
|
95
130
|
console.log('Volume button pressed:', event.direction);
|
|
96
131
|
});
|
|
97
132
|
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Listen for volume changes
|
|
136
|
+
|
|
137
|
+
Get notified when the volume level changes. The event is only emitted while watching (see above):
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { Volume } from '@capawesome/capacitor-volume';
|
|
98
141
|
|
|
99
142
|
const addVolumeChangeListener = async () => {
|
|
100
143
|
await Volume.addListener('volumeChange', event => {
|
|
101
144
|
console.log('Volume changed:', event.volume);
|
|
102
145
|
});
|
|
103
146
|
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Remove all listeners
|
|
150
|
+
|
|
151
|
+
Remove all listeners for this plugin when they are no longer needed:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { Volume } from '@capawesome/capacitor-volume';
|
|
104
155
|
|
|
105
156
|
const removeAllListeners = async () => {
|
|
106
157
|
await Volume.removeAllListeners();
|
|
@@ -373,12 +424,12 @@ The direction of a hardware volume button.
|
|
|
373
424
|
|
|
374
425
|
| Members | Value | Description | Since |
|
|
375
426
|
| ------------------ | --------------------------- | ---------------------------------------------- | ----- |
|
|
376
|
-
| **`Alarm`** | <code>'
|
|
377
|
-
| **`Music`** | <code>'
|
|
378
|
-
| **`Notification`** | <code>'
|
|
379
|
-
| **`Ring`** | <code>'
|
|
380
|
-
| **`System`** | <code>'
|
|
381
|
-
| **`VoiceCall`** | <code>'
|
|
427
|
+
| **`Alarm`** | <code>'ALARM'</code> | The audio stream for alarms. | 0.1.0 |
|
|
428
|
+
| **`Music`** | <code>'MUSIC'</code> | The audio stream for music and media playback. | 0.1.0 |
|
|
429
|
+
| **`Notification`** | <code>'NOTIFICATION'</code> | The audio stream for notifications. | 0.1.0 |
|
|
430
|
+
| **`Ring`** | <code>'RING'</code> | The audio stream for the phone ring. | 0.1.0 |
|
|
431
|
+
| **`System`** | <code>'SYSTEM'</code> | The audio stream for system sounds. | 0.1.0 |
|
|
432
|
+
| **`VoiceCall`** | <code>'VOICE_CALL'</code> | The audio stream for phone calls. | 0.1.0 |
|
|
382
433
|
|
|
383
434
|
</docgen-api>
|
|
384
435
|
|
|
@@ -396,6 +447,46 @@ Keep the following platform differences in mind when watching the hardware volum
|
|
|
396
447
|
- **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
448
|
- **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
449
|
|
|
450
|
+
## FAQ
|
|
451
|
+
|
|
452
|
+
### How is this plugin different from other similar plugins?
|
|
453
|
+
|
|
454
|
+
It combines volume control and hardware button events in one unified API — a natural fit on iOS, where both rely on the same underlying system machinery. It adds per-stream control on Android and handles iOS volume-indicator suppression, all through a fully typed, actively maintained package, so a single dependency covers the whole volume story.
|
|
455
|
+
|
|
456
|
+
### Which platforms are supported by this plugin?
|
|
457
|
+
|
|
458
|
+
The plugin is available on Android and iOS. On the Web, all methods reject as unimplemented.
|
|
459
|
+
|
|
460
|
+
### Why is the `stream` option ignored on iOS?
|
|
461
|
+
|
|
462
|
+
On 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 on iOS. The `stream` option is only supported on Android, see [Volume Control](#volume-control) for details.
|
|
463
|
+
|
|
464
|
+
### Why is `setVolume` rejected with the `DO_NOT_DISTURB_ACCESS_REQUIRED` error code?
|
|
465
|
+
|
|
466
|
+
On Android, changing the volume of the ring, notification or system stream while Do Not Disturb is active requires Do Not Disturb access. You can direct the user to the corresponding settings screen using the `ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS` intent, for example with the App Launcher plugin, see [Volume Control](#volume-control) for details.
|
|
467
|
+
|
|
468
|
+
### Why are volume button presses not detected?
|
|
469
|
+
|
|
470
|
+
The `volumeButtonPressed` event is only emitted while watching, so make sure you have called `startWatching(...)` first. On both platforms, button presses are only detected while the app is in the foreground. On iOS, presses can also not be detected once the volume has reached its minimum or maximum unless the `suppressVolumeChange` option is enabled, see [Volume Button Watching](#volume-button-watching) for details.
|
|
471
|
+
|
|
472
|
+
### What does the `suppressVolumeChange` option do?
|
|
473
|
+
|
|
474
|
+
With this option enabled, pressing a hardware volume button while watching does not change the volume and the system volume indicator stays hidden. On Android, the volume key events are consumed. On iOS, the volume level is reset immediately after each button press and the original volume level is restored when watching stops.
|
|
475
|
+
|
|
476
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
477
|
+
|
|
478
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
479
|
+
|
|
480
|
+
## Related Plugins
|
|
481
|
+
|
|
482
|
+
- [Media Session](https://capawesome.io/docs/sdks/capacitor/media-session/): Interact with media controllers, volume keys and media buttons.
|
|
483
|
+
- [Silent Mode](https://capawesome.io/docs/sdks/capacitor/silent-mode/): Detect whether the device is in silent mode.
|
|
484
|
+
- [Audio Session](https://capawesome.io/docs/sdks/capacitor/audio-session/): Configure and observe the iOS audio session.
|
|
485
|
+
|
|
486
|
+
## Newsletter
|
|
487
|
+
|
|
488
|
+
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/).
|
|
489
|
+
|
|
399
490
|
## Changelog
|
|
400
491
|
|
|
401
492
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/volume/CHANGELOG.md).
|
|
@@ -8,17 +8,17 @@ public class VolumeHelper {
|
|
|
8
8
|
|
|
9
9
|
public static int mapStreamToStreamType(@NonNull String stream) throws Exception {
|
|
10
10
|
switch (stream) {
|
|
11
|
-
case "
|
|
11
|
+
case "ALARM":
|
|
12
12
|
return AudioManager.STREAM_ALARM;
|
|
13
|
-
case "
|
|
13
|
+
case "MUSIC":
|
|
14
14
|
return AudioManager.STREAM_MUSIC;
|
|
15
|
-
case "
|
|
15
|
+
case "NOTIFICATION":
|
|
16
16
|
return AudioManager.STREAM_NOTIFICATION;
|
|
17
|
-
case "
|
|
17
|
+
case "RING":
|
|
18
18
|
return AudioManager.STREAM_RING;
|
|
19
|
-
case "
|
|
19
|
+
case "SYSTEM":
|
|
20
20
|
return AudioManager.STREAM_SYSTEM;
|
|
21
|
-
case "
|
|
21
|
+
case "VOICE_CALL":
|
|
22
22
|
return AudioManager.STREAM_VOICE_CALL;
|
|
23
23
|
default:
|
|
24
24
|
throw CustomExceptions.STREAM_INVALID;
|
|
@@ -17,7 +17,7 @@ public class GetVolumeOptions {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
private static int getStreamTypeFromCall(@NonNull PluginCall call) throws Exception {
|
|
20
|
-
String stream = call.getString("stream", "
|
|
20
|
+
String stream = call.getString("stream", "MUSIC");
|
|
21
21
|
return VolumeHelper.mapStreamToStreamType(stream);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -24,7 +24,7 @@ public class SetVolumeOptions {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
private static int getStreamTypeFromCall(@NonNull PluginCall call) throws Exception {
|
|
27
|
-
String stream = call.getString("stream", "
|
|
27
|
+
String stream = call.getString("stream", "MUSIC");
|
|
28
28
|
return VolumeHelper.mapStreamToStreamType(stream);
|
|
29
29
|
}
|
|
30
30
|
|
package/dist/docs.json
CHANGED
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
"name": "default"
|
|
239
239
|
},
|
|
240
240
|
{
|
|
241
|
-
"text": "'
|
|
241
|
+
"text": "'MUSIC'",
|
|
242
242
|
"name": "example"
|
|
243
243
|
}
|
|
244
244
|
],
|
|
@@ -304,7 +304,7 @@
|
|
|
304
304
|
"name": "default"
|
|
305
305
|
},
|
|
306
306
|
{
|
|
307
|
-
"text": "'
|
|
307
|
+
"text": "'MUSIC'",
|
|
308
308
|
"name": "example"
|
|
309
309
|
}
|
|
310
310
|
],
|
|
@@ -452,7 +452,7 @@
|
|
|
452
452
|
"members": [
|
|
453
453
|
{
|
|
454
454
|
"name": "Alarm",
|
|
455
|
-
"value": "'
|
|
455
|
+
"value": "'ALARM'",
|
|
456
456
|
"tags": [
|
|
457
457
|
{
|
|
458
458
|
"text": "0.1.0",
|
|
@@ -463,7 +463,7 @@
|
|
|
463
463
|
},
|
|
464
464
|
{
|
|
465
465
|
"name": "Music",
|
|
466
|
-
"value": "'
|
|
466
|
+
"value": "'MUSIC'",
|
|
467
467
|
"tags": [
|
|
468
468
|
{
|
|
469
469
|
"text": "0.1.0",
|
|
@@ -474,7 +474,7 @@
|
|
|
474
474
|
},
|
|
475
475
|
{
|
|
476
476
|
"name": "Notification",
|
|
477
|
-
"value": "'
|
|
477
|
+
"value": "'NOTIFICATION'",
|
|
478
478
|
"tags": [
|
|
479
479
|
{
|
|
480
480
|
"text": "0.1.0",
|
|
@@ -485,7 +485,7 @@
|
|
|
485
485
|
},
|
|
486
486
|
{
|
|
487
487
|
"name": "Ring",
|
|
488
|
-
"value": "'
|
|
488
|
+
"value": "'RING'",
|
|
489
489
|
"tags": [
|
|
490
490
|
{
|
|
491
491
|
"text": "0.1.0",
|
|
@@ -496,7 +496,7 @@
|
|
|
496
496
|
},
|
|
497
497
|
{
|
|
498
498
|
"name": "System",
|
|
499
|
-
"value": "'
|
|
499
|
+
"value": "'SYSTEM'",
|
|
500
500
|
"tags": [
|
|
501
501
|
{
|
|
502
502
|
"text": "0.1.0",
|
|
@@ -507,7 +507,7 @@
|
|
|
507
507
|
},
|
|
508
508
|
{
|
|
509
509
|
"name": "VoiceCall",
|
|
510
|
-
"value": "'
|
|
510
|
+
"value": "'VOICE_CALL'",
|
|
511
511
|
"tags": [
|
|
512
512
|
{
|
|
513
513
|
"text": "0.1.0",
|
|
@@ -91,7 +91,7 @@ export interface GetVolumeOptions {
|
|
|
91
91
|
*
|
|
92
92
|
* @since 0.1.0
|
|
93
93
|
* @default VolumeStream.Music
|
|
94
|
-
* @example '
|
|
94
|
+
* @example 'MUSIC'
|
|
95
95
|
*/
|
|
96
96
|
stream?: VolumeStream;
|
|
97
97
|
}
|
|
@@ -118,7 +118,7 @@ export interface SetVolumeOptions {
|
|
|
118
118
|
*
|
|
119
119
|
* @since 0.1.0
|
|
120
120
|
* @default VolumeStream.Music
|
|
121
|
-
* @example '
|
|
121
|
+
* @example 'MUSIC'
|
|
122
122
|
*/
|
|
123
123
|
stream?: VolumeStream;
|
|
124
124
|
/**
|
|
@@ -207,37 +207,37 @@ export declare enum VolumeStream {
|
|
|
207
207
|
*
|
|
208
208
|
* @since 0.1.0
|
|
209
209
|
*/
|
|
210
|
-
Alarm = "
|
|
210
|
+
Alarm = "ALARM",
|
|
211
211
|
/**
|
|
212
212
|
* The audio stream for music and media playback.
|
|
213
213
|
*
|
|
214
214
|
* @since 0.1.0
|
|
215
215
|
*/
|
|
216
|
-
Music = "
|
|
216
|
+
Music = "MUSIC",
|
|
217
217
|
/**
|
|
218
218
|
* The audio stream for notifications.
|
|
219
219
|
*
|
|
220
220
|
* @since 0.1.0
|
|
221
221
|
*/
|
|
222
|
-
Notification = "
|
|
222
|
+
Notification = "NOTIFICATION",
|
|
223
223
|
/**
|
|
224
224
|
* The audio stream for the phone ring.
|
|
225
225
|
*
|
|
226
226
|
* @since 0.1.0
|
|
227
227
|
*/
|
|
228
|
-
Ring = "
|
|
228
|
+
Ring = "RING",
|
|
229
229
|
/**
|
|
230
230
|
* The audio stream for system sounds.
|
|
231
231
|
*
|
|
232
232
|
* @since 0.1.0
|
|
233
233
|
*/
|
|
234
|
-
System = "
|
|
234
|
+
System = "SYSTEM",
|
|
235
235
|
/**
|
|
236
236
|
* The audio stream for phone calls.
|
|
237
237
|
*
|
|
238
238
|
* @since 0.1.0
|
|
239
239
|
*/
|
|
240
|
-
VoiceCall = "
|
|
240
|
+
VoiceCall = "VOICE_CALL"
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
243
243
|
* @since 0.1.0
|
package/dist/esm/definitions.js
CHANGED
|
@@ -10,37 +10,37 @@ export var VolumeStream;
|
|
|
10
10
|
*
|
|
11
11
|
* @since 0.1.0
|
|
12
12
|
*/
|
|
13
|
-
VolumeStream["Alarm"] = "
|
|
13
|
+
VolumeStream["Alarm"] = "ALARM";
|
|
14
14
|
/**
|
|
15
15
|
* The audio stream for music and media playback.
|
|
16
16
|
*
|
|
17
17
|
* @since 0.1.0
|
|
18
18
|
*/
|
|
19
|
-
VolumeStream["Music"] = "
|
|
19
|
+
VolumeStream["Music"] = "MUSIC";
|
|
20
20
|
/**
|
|
21
21
|
* The audio stream for notifications.
|
|
22
22
|
*
|
|
23
23
|
* @since 0.1.0
|
|
24
24
|
*/
|
|
25
|
-
VolumeStream["Notification"] = "
|
|
25
|
+
VolumeStream["Notification"] = "NOTIFICATION";
|
|
26
26
|
/**
|
|
27
27
|
* The audio stream for the phone ring.
|
|
28
28
|
*
|
|
29
29
|
* @since 0.1.0
|
|
30
30
|
*/
|
|
31
|
-
VolumeStream["Ring"] = "
|
|
31
|
+
VolumeStream["Ring"] = "RING";
|
|
32
32
|
/**
|
|
33
33
|
* The audio stream for system sounds.
|
|
34
34
|
*
|
|
35
35
|
* @since 0.1.0
|
|
36
36
|
*/
|
|
37
|
-
VolumeStream["System"] = "
|
|
37
|
+
VolumeStream["System"] = "SYSTEM";
|
|
38
38
|
/**
|
|
39
39
|
* The audio stream for phone calls.
|
|
40
40
|
*
|
|
41
41
|
* @since 0.1.0
|
|
42
42
|
*/
|
|
43
|
-
VolumeStream["VoiceCall"] = "
|
|
43
|
+
VolumeStream["VoiceCall"] = "VOICE_CALL";
|
|
44
44
|
})(VolumeStream || (VolumeStream = {}));
|
|
45
45
|
/**
|
|
46
46
|
* @since 0.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAsNA;;;;GAIG;AACH,MAAM,CAAN,IAAY,YAqCX;AArCD,WAAY,YAAY;IACtB;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;OAIG;IACH,6CAA6B,CAAA;IAC7B;;;;OAIG;IACH,6BAAa,CAAA;IACb;;;;OAIG;IACH,iCAAiB,CAAA;IACjB;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAsNA;;;;GAIG;AACH,MAAM,CAAN,IAAY,YAqCX;AArCD,WAAY,YAAY;IACtB;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;OAIG;IACH,+BAAe,CAAA;IACf;;;;OAIG;IACH,6CAA6B,CAAA;IAC7B;;;;OAIG;IACH,6BAAa,CAAA;IACb;;;;OAIG;IACH,iCAAiB,CAAA;IACjB;;;;OAIG;IACH,wCAAwB,CAAA;AAC1B,CAAC,EArCW,YAAY,KAAZ,YAAY,QAqCvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,SAUX;AAVD,WAAY,SAAS;IACnB;;;;;;;OAOG;IACH,0EAA6D,CAAA;AAC/D,CAAC,EAVW,SAAS,KAAT,SAAS,QAUpB","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface VolumePlugin {\n /**\n * Get the current volume level.\n *\n * On iOS, this always returns the media volume.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n getVolume(options?: GetVolumeOptions): Promise<GetVolumeResult>;\n /**\n * Check whether the hardware volume buttons are currently being watched.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n isWatching(): Promise<IsWatchingResult>;\n /**\n * Set the volume level.\n *\n * On iOS, this always sets the media volume.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n setVolume(options: SetVolumeOptions): Promise<void>;\n /**\n * Start watching the hardware volume buttons.\n *\n * The `volumeButtonPressed` and `volumeChange` events are only\n * emitted while watching.\n *\n * If the volume buttons are already being watched, this call has\n * no effect. Call `stopWatching()` first to change the options.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n startWatching(options?: StartWatchingOptions): Promise<void>;\n /**\n * Stop watching the hardware volume buttons.\n *\n * On iOS, this also restores the volume level that was set when\n * watching started if the `suppressVolumeChange` option was enabled.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n stopWatching(): Promise<void>;\n /**\n * Called when a hardware volume button is pressed while watching.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'volumeButtonPressed',\n listenerFunc: (event: VolumeButtonPressedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the volume level changes while watching.\n *\n * On Android, this is called for changes to the music stream.\n * On iOS, this is called for changes to the media volume and is\n * not called while the `suppressVolumeChange` option is enabled.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'volumeChange',\n listenerFunc: (event: VolumeChangeEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetVolumeOptions {\n /**\n * The audio stream to get the volume for.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n * @default VolumeStream.Music\n * @example 'MUSIC'\n */\n stream?: VolumeStream;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetVolumeResult {\n /**\n * The current volume level as a value between `0` and `1`.\n *\n * @since 0.1.0\n * @example 0.5\n */\n volume: number;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface SetVolumeOptions {\n /**\n * The audio stream to set the volume for.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n * @default VolumeStream.Music\n * @example 'MUSIC'\n */\n stream?: VolumeStream;\n /**\n * The volume level to set as a value between `0` and `1`.\n *\n * @since 0.1.0\n * @example 0.5\n */\n volume: number;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface StartWatchingOptions {\n /**\n * Whether to keep the volume level unchanged when a hardware volume\n * button is pressed while watching.\n *\n * On Android, the volume key events are consumed so that the system\n * does not apply the volume change or display the volume panel.\n * On iOS, the volume level is reset immediately after each button\n * press and the system volume indicator is hidden. If the volume\n * level is close to the minimum or maximum, it is nudged to a value\n * from which both buttons can still be detected. The original volume\n * level is restored when watching stops.\n *\n * @since 0.1.0\n * @default false\n * @example true\n */\n suppressVolumeChange?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface IsWatchingResult {\n /**\n * Whether the hardware volume buttons are currently being watched.\n *\n * @since 0.1.0\n * @example true\n */\n watching: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface VolumeButtonPressedEvent {\n /**\n * The direction of the pressed hardware volume button.\n *\n * @since 0.1.0\n * @example 'up'\n */\n direction: Direction;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface VolumeChangeEvent {\n /**\n * The new volume level as a value between `0` and `1`.\n *\n * @since 0.1.0\n * @example 0.5\n */\n volume: number;\n}\n\n/**\n * The direction of a hardware volume button.\n *\n * - `up`: The volume up button.\n * - `down`: The volume down button.\n *\n * @since 0.1.0\n */\nexport type Direction = 'down' | 'up';\n\n/**\n * The audio stream of the device.\n *\n * @since 0.1.0\n */\nexport enum VolumeStream {\n /**\n * The audio stream for alarms.\n *\n * @since 0.1.0\n */\n Alarm = 'ALARM',\n /**\n * The audio stream for music and media playback.\n *\n * @since 0.1.0\n */\n Music = 'MUSIC',\n /**\n * The audio stream for notifications.\n *\n * @since 0.1.0\n */\n Notification = 'NOTIFICATION',\n /**\n * The audio stream for the phone ring.\n *\n * @since 0.1.0\n */\n Ring = 'RING',\n /**\n * The audio stream for system sounds.\n *\n * @since 0.1.0\n */\n System = 'SYSTEM',\n /**\n * The audio stream for phone calls.\n *\n * @since 0.1.0\n */\n VoiceCall = 'VOICE_CALL',\n}\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * Do Not Disturb access is required to change the volume of the\n * ring, notification or system stream while Do Not Disturb is active.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n DoNotDisturbAccessRequired = 'DO_NOT_DISTURB_ACCESS_REQUIRED',\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -14,37 +14,37 @@ exports.VolumeStream = void 0;
|
|
|
14
14
|
*
|
|
15
15
|
* @since 0.1.0
|
|
16
16
|
*/
|
|
17
|
-
VolumeStream["Alarm"] = "
|
|
17
|
+
VolumeStream["Alarm"] = "ALARM";
|
|
18
18
|
/**
|
|
19
19
|
* The audio stream for music and media playback.
|
|
20
20
|
*
|
|
21
21
|
* @since 0.1.0
|
|
22
22
|
*/
|
|
23
|
-
VolumeStream["Music"] = "
|
|
23
|
+
VolumeStream["Music"] = "MUSIC";
|
|
24
24
|
/**
|
|
25
25
|
* The audio stream for notifications.
|
|
26
26
|
*
|
|
27
27
|
* @since 0.1.0
|
|
28
28
|
*/
|
|
29
|
-
VolumeStream["Notification"] = "
|
|
29
|
+
VolumeStream["Notification"] = "NOTIFICATION";
|
|
30
30
|
/**
|
|
31
31
|
* The audio stream for the phone ring.
|
|
32
32
|
*
|
|
33
33
|
* @since 0.1.0
|
|
34
34
|
*/
|
|
35
|
-
VolumeStream["Ring"] = "
|
|
35
|
+
VolumeStream["Ring"] = "RING";
|
|
36
36
|
/**
|
|
37
37
|
* The audio stream for system sounds.
|
|
38
38
|
*
|
|
39
39
|
* @since 0.1.0
|
|
40
40
|
*/
|
|
41
|
-
VolumeStream["System"] = "
|
|
41
|
+
VolumeStream["System"] = "SYSTEM";
|
|
42
42
|
/**
|
|
43
43
|
* The audio stream for phone calls.
|
|
44
44
|
*
|
|
45
45
|
* @since 0.1.0
|
|
46
46
|
*/
|
|
47
|
-
VolumeStream["VoiceCall"] = "
|
|
47
|
+
VolumeStream["VoiceCall"] = "VOICE_CALL";
|
|
48
48
|
})(exports.VolumeStream || (exports.VolumeStream = {}));
|
|
49
49
|
/**
|
|
50
50
|
* @since 0.1.0
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The audio stream of the device.\n *\n * @since 0.1.0\n */\nexport var VolumeStream;\n(function (VolumeStream) {\n /**\n * The audio stream for alarms.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Alarm\"] = \"
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The audio stream of the device.\n *\n * @since 0.1.0\n */\nexport var VolumeStream;\n(function (VolumeStream) {\n /**\n * The audio stream for alarms.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Alarm\"] = \"ALARM\";\n /**\n * The audio stream for music and media playback.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Music\"] = \"MUSIC\";\n /**\n * The audio stream for notifications.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Notification\"] = \"NOTIFICATION\";\n /**\n * The audio stream for the phone ring.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Ring\"] = \"RING\";\n /**\n * The audio stream for system sounds.\n *\n * @since 0.1.0\n */\n VolumeStream[\"System\"] = \"SYSTEM\";\n /**\n * The audio stream for phone calls.\n *\n * @since 0.1.0\n */\n VolumeStream[\"VoiceCall\"] = \"VOICE_CALL\";\n})(VolumeStream || (VolumeStream = {}));\n/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * Do Not Disturb access is required to change the volume of the\n * ring, notification or system stream while Do Not Disturb is active.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n ErrorCode[\"DoNotDisturbAccessRequired\"] = \"DO_NOT_DISTURB_ACCESS_REQUIRED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Volume = registerPlugin('Volume', {\n web: () => import('./web').then(m => new m.VolumeWeb()),\n});\nexport * from './definitions';\nexport { Volume };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class VolumeWeb extends WebPlugin {\n async getVolume() {\n throw this.unimplemented('Not implemented on web.');\n }\n async isWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setVolume() {\n throw this.unimplemented('Not implemented on web.');\n }\n async startWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["VolumeStream","ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,YAAY,EAAE;AACzB;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO;AACnC;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO;AACnC;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,cAAc,CAAC,GAAG,cAAc;AACjD;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM;AACjC;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACrC;AACA;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,WAAW,CAAC,GAAG,YAAY;AAC5C,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;AACvC;AACA;AACA;AACWC;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,4BAA4B,CAAC,GAAG,gCAAgC;AAC9E,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACzD5B,MAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;AACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;AAC3D,CAAC;;ACFM,MAAM,SAAS,SAASC,cAAS,CAAC;AACzC,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -13,37 +13,37 @@ var capacitorVolume = (function (exports, core) {
|
|
|
13
13
|
*
|
|
14
14
|
* @since 0.1.0
|
|
15
15
|
*/
|
|
16
|
-
VolumeStream["Alarm"] = "
|
|
16
|
+
VolumeStream["Alarm"] = "ALARM";
|
|
17
17
|
/**
|
|
18
18
|
* The audio stream for music and media playback.
|
|
19
19
|
*
|
|
20
20
|
* @since 0.1.0
|
|
21
21
|
*/
|
|
22
|
-
VolumeStream["Music"] = "
|
|
22
|
+
VolumeStream["Music"] = "MUSIC";
|
|
23
23
|
/**
|
|
24
24
|
* The audio stream for notifications.
|
|
25
25
|
*
|
|
26
26
|
* @since 0.1.0
|
|
27
27
|
*/
|
|
28
|
-
VolumeStream["Notification"] = "
|
|
28
|
+
VolumeStream["Notification"] = "NOTIFICATION";
|
|
29
29
|
/**
|
|
30
30
|
* The audio stream for the phone ring.
|
|
31
31
|
*
|
|
32
32
|
* @since 0.1.0
|
|
33
33
|
*/
|
|
34
|
-
VolumeStream["Ring"] = "
|
|
34
|
+
VolumeStream["Ring"] = "RING";
|
|
35
35
|
/**
|
|
36
36
|
* The audio stream for system sounds.
|
|
37
37
|
*
|
|
38
38
|
* @since 0.1.0
|
|
39
39
|
*/
|
|
40
|
-
VolumeStream["System"] = "
|
|
40
|
+
VolumeStream["System"] = "SYSTEM";
|
|
41
41
|
/**
|
|
42
42
|
* The audio stream for phone calls.
|
|
43
43
|
*
|
|
44
44
|
* @since 0.1.0
|
|
45
45
|
*/
|
|
46
|
-
VolumeStream["VoiceCall"] = "
|
|
46
|
+
VolumeStream["VoiceCall"] = "VOICE_CALL";
|
|
47
47
|
})(exports.VolumeStream || (exports.VolumeStream = {}));
|
|
48
48
|
/**
|
|
49
49
|
* @since 0.1.0
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The audio stream of the device.\n *\n * @since 0.1.0\n */\nexport var VolumeStream;\n(function (VolumeStream) {\n /**\n * The audio stream for alarms.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Alarm\"] = \"
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The audio stream of the device.\n *\n * @since 0.1.0\n */\nexport var VolumeStream;\n(function (VolumeStream) {\n /**\n * The audio stream for alarms.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Alarm\"] = \"ALARM\";\n /**\n * The audio stream for music and media playback.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Music\"] = \"MUSIC\";\n /**\n * The audio stream for notifications.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Notification\"] = \"NOTIFICATION\";\n /**\n * The audio stream for the phone ring.\n *\n * @since 0.1.0\n */\n VolumeStream[\"Ring\"] = \"RING\";\n /**\n * The audio stream for system sounds.\n *\n * @since 0.1.0\n */\n VolumeStream[\"System\"] = \"SYSTEM\";\n /**\n * The audio stream for phone calls.\n *\n * @since 0.1.0\n */\n VolumeStream[\"VoiceCall\"] = \"VOICE_CALL\";\n})(VolumeStream || (VolumeStream = {}));\n/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * Do Not Disturb access is required to change the volume of the\n * ring, notification or system stream while Do Not Disturb is active.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n ErrorCode[\"DoNotDisturbAccessRequired\"] = \"DO_NOT_DISTURB_ACCESS_REQUIRED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Volume = registerPlugin('Volume', {\n web: () => import('./web').then(m => new m.VolumeWeb()),\n});\nexport * from './definitions';\nexport { Volume };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class VolumeWeb extends WebPlugin {\n async getVolume() {\n throw this.unimplemented('Not implemented on web.');\n }\n async isWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setVolume() {\n throw this.unimplemented('Not implemented on web.');\n }\n async startWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopWatching() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["VolumeStream","ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,YAAY,EAAE;IACzB;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO;IACnC;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO;IACnC;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,cAAc,CAAC,GAAG,cAAc;IACjD;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM;IACjC;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACrC;IACA;IACA;IACA;IACA;IACA,IAAI,YAAY,CAAC,WAAW,CAAC,GAAG,YAAY;IAC5C,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC;IACvC;IACA;IACA;AACWC;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,4BAA4B,CAAC,GAAG,gCAAgC;IAC9E,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACzD5B,UAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3D,CAAC;;ICFM,MAAM,SAAS,SAASC,cAAS,CAAC;IACzC,IAAI,MAAM,SAAS,GAAG;IACtB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,SAAS,GAAG;IACtB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-volume",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Capacitor plugin to control the volume and observe hardware volume button presses.",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Capacitor plugin to control the volume and observe hardware volume button presses on Android and iOS.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -33,11 +33,18 @@
|
|
|
33
33
|
"url": "https://opencollective.com/capawesome"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
-
"homepage": "https://capawesome.io/docs/
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/volume/",
|
|
37
37
|
"keywords": [
|
|
38
38
|
"capacitor",
|
|
39
39
|
"plugin",
|
|
40
|
-
"native"
|
|
40
|
+
"native",
|
|
41
|
+
"capacitor-plugin",
|
|
42
|
+
"volume",
|
|
43
|
+
"volume control",
|
|
44
|
+
"volume buttons",
|
|
45
|
+
"hardware buttons",
|
|
46
|
+
"audio stream",
|
|
47
|
+
"media volume"
|
|
41
48
|
],
|
|
42
49
|
"scripts": {
|
|
43
50
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|