react-native-audio-api 0.11.0-nightly-b30bac9-20260114 → 0.11.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.
Files changed (173) hide show
  1. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +3 -10
  2. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +0 -4
  3. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +4 -83
  4. package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +14 -29
  5. package/android/src/main/java/com/swmansion/audioapi/system/ForegroundServiceManager.kt +10 -9
  6. package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +10 -51
  7. package/android/src/main/java/com/swmansion/audioapi/system/notification/BaseNotification.kt +6 -14
  8. package/android/src/main/java/com/swmansion/audioapi/system/notification/NotificationRegistry.kt +79 -60
  9. package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +249 -411
  10. package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotificationReceiver.kt +8 -3
  11. package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotification.kt +240 -222
  12. package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +11 -22
  13. package/android/src/main/java/com/swmansion/audioapi/system/notification/state/RecordingNotificationState.kt +24 -0
  14. package/android/src/main/res/layout/btn_round_ripple.xml +9 -0
  15. package/android/src/main/res/layout/notification_collapsed.xml +45 -0
  16. package/android/src/main/res/layout/notification_expanded.xml +44 -0
  17. package/android/src/oldarch/NativeAudioAPIModuleSpec.java +1 -13
  18. package/common/cpp/audioapi/core/utils/AudioFileWriter.cpp +1 -1
  19. package/ios/audioapi/ios/AudioAPIModule.mm +5 -48
  20. package/ios/audioapi/ios/system/notification/BaseNotification.h +0 -7
  21. package/ios/audioapi/ios/system/notification/NotificationRegistry.h +5 -25
  22. package/ios/audioapi/ios/system/notification/NotificationRegistry.mm +19 -64
  23. package/ios/audioapi/ios/system/notification/PlaybackNotification.mm +4 -15
  24. package/lib/commonjs/AudioAPIModule/AudioAPIModule.js +2 -1
  25. package/lib/commonjs/AudioAPIModule/AudioAPIModule.js.map +1 -1
  26. package/lib/commonjs/api.js +1 -29
  27. package/lib/commonjs/api.js.map +1 -1
  28. package/lib/commonjs/core/AudioDecoder.js +42 -16
  29. package/lib/commonjs/core/AudioDecoder.js.map +1 -1
  30. package/lib/commonjs/core/AudioRecorder.js +2 -1
  31. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  32. package/lib/commonjs/core/AudioStretcher.js +2 -1
  33. package/lib/commonjs/core/AudioStretcher.js.map +1 -1
  34. package/lib/commonjs/core/BaseAudioContext.js +2 -5
  35. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  36. package/lib/commonjs/errors/AudioApiError.js +14 -0
  37. package/lib/commonjs/errors/AudioApiError.js.map +1 -0
  38. package/lib/commonjs/errors/index.js +7 -0
  39. package/lib/commonjs/errors/index.js.map +1 -1
  40. package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
  41. package/lib/commonjs/specs/NativeAudioAPIModule.web.js +0 -9
  42. package/lib/commonjs/specs/NativeAudioAPIModule.web.js.map +1 -1
  43. package/lib/commonjs/system/notification/PlaybackNotificationManager.js +40 -85
  44. package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -1
  45. package/lib/commonjs/system/notification/RecordingNotificationManager.ios.js +51 -0
  46. package/lib/commonjs/system/notification/RecordingNotificationManager.ios.js.map +1 -0
  47. package/lib/commonjs/system/notification/RecordingNotificationManager.js +30 -144
  48. package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -1
  49. package/lib/commonjs/system/notification/index.js +1 -9
  50. package/lib/commonjs/system/notification/index.js.map +1 -1
  51. package/lib/commonjs/utils/index.js +3 -2
  52. package/lib/commonjs/utils/index.js.map +1 -1
  53. package/lib/commonjs/utils/paths.js +18 -0
  54. package/lib/commonjs/utils/paths.js.map +1 -0
  55. package/lib/commonjs/web-core/AudioContext.js +20 -11
  56. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  57. package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +0 -1
  58. package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -1
  59. package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +1 -6
  60. package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -1
  61. package/lib/module/AudioAPIModule/AudioAPIModule.js +2 -1
  62. package/lib/module/AudioAPIModule/AudioAPIModule.js.map +1 -1
  63. package/lib/module/api.js +3 -2
  64. package/lib/module/api.js.map +1 -1
  65. package/lib/module/core/AudioDecoder.js +42 -16
  66. package/lib/module/core/AudioDecoder.js.map +1 -1
  67. package/lib/module/core/AudioRecorder.js +3 -1
  68. package/lib/module/core/AudioRecorder.js.map +1 -1
  69. package/lib/module/core/AudioStretcher.js +2 -1
  70. package/lib/module/core/AudioStretcher.js.map +1 -1
  71. package/lib/module/core/BaseAudioContext.js +2 -5
  72. package/lib/module/core/BaseAudioContext.js.map +1 -1
  73. package/lib/module/errors/AudioApiError.js +10 -0
  74. package/lib/module/errors/AudioApiError.js.map +1 -0
  75. package/lib/module/errors/index.js +1 -0
  76. package/lib/module/errors/index.js.map +1 -1
  77. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
  78. package/lib/module/specs/NativeAudioAPIModule.web.js +0 -9
  79. package/lib/module/specs/NativeAudioAPIModule.web.js.map +1 -1
  80. package/lib/module/system/notification/PlaybackNotificationManager.js +40 -85
  81. package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -1
  82. package/lib/module/system/notification/RecordingNotificationManager.ios.js +47 -0
  83. package/lib/module/system/notification/RecordingNotificationManager.ios.js.map +1 -0
  84. package/lib/module/system/notification/RecordingNotificationManager.js +30 -144
  85. package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -1
  86. package/lib/module/system/notification/index.js +1 -2
  87. package/lib/module/system/notification/index.js.map +1 -1
  88. package/lib/module/utils/index.js +3 -2
  89. package/lib/module/utils/index.js.map +1 -1
  90. package/lib/module/utils/paths.js +12 -0
  91. package/lib/module/utils/paths.js.map +1 -0
  92. package/lib/module/web-core/AudioContext.js +20 -11
  93. package/lib/module/web-core/AudioContext.js.map +1 -1
  94. package/lib/module/web-system/notification/PlaybackNotificationManager.js +0 -1
  95. package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -1
  96. package/lib/module/web-system/notification/RecordingNotificationManager.js +1 -6
  97. package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -1
  98. package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts.map +1 -1
  99. package/lib/typescript/api.d.ts +3 -2
  100. package/lib/typescript/api.d.ts.map +1 -1
  101. package/lib/typescript/core/AudioDecoder.d.ts +2 -1
  102. package/lib/typescript/core/AudioDecoder.d.ts.map +1 -1
  103. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  104. package/lib/typescript/core/AudioStretcher.d.ts.map +1 -1
  105. package/lib/typescript/core/BaseAudioContext.d.ts +2 -2
  106. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  107. package/lib/typescript/errors/AudioApiError.d.ts +5 -0
  108. package/lib/typescript/errors/AudioApiError.d.ts.map +1 -0
  109. package/lib/typescript/errors/index.d.ts +1 -0
  110. package/lib/typescript/errors/index.d.ts.map +1 -1
  111. package/lib/typescript/interfaces.d.ts +1 -1
  112. package/lib/typescript/interfaces.d.ts.map +1 -1
  113. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +2 -5
  114. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
  115. package/lib/typescript/specs/NativeAudioAPIModule.web.d.ts +1 -4
  116. package/lib/typescript/specs/NativeAudioAPIModule.web.d.ts.map +1 -1
  117. package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +32 -9
  118. package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -1
  119. package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +26 -13
  120. package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -1
  121. package/lib/typescript/system/notification/RecordingNotificationManager.ios.d.ts +36 -0
  122. package/lib/typescript/system/notification/RecordingNotificationManager.ios.d.ts.map +1 -0
  123. package/lib/typescript/system/notification/index.d.ts +0 -1
  124. package/lib/typescript/system/notification/index.d.ts.map +1 -1
  125. package/lib/typescript/system/notification/types.d.ts +12 -22
  126. package/lib/typescript/system/notification/types.d.ts.map +1 -1
  127. package/lib/typescript/types.d.ts +1 -0
  128. package/lib/typescript/types.d.ts.map +1 -1
  129. package/lib/typescript/utils/index.d.ts.map +1 -1
  130. package/lib/typescript/utils/paths.d.ts +4 -0
  131. package/lib/typescript/utils/paths.d.ts.map +1 -0
  132. package/lib/typescript/web-core/AudioContext.d.ts +8 -9
  133. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  134. package/lib/typescript/web-core/BaseAudioContext.d.ts +6 -7
  135. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  136. package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +1 -2
  137. package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -1
  138. package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +2 -7
  139. package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -1
  140. package/package.json +1 -1
  141. package/src/AudioAPIModule/AudioAPIModule.ts +2 -1
  142. package/src/api.ts +2 -8
  143. package/src/core/AudioDecoder.ts +91 -21
  144. package/src/core/AudioRecorder.ts +2 -1
  145. package/src/core/AudioStretcher.ts +2 -1
  146. package/src/core/BaseAudioContext.ts +4 -6
  147. package/src/errors/AudioApiError.ts +8 -0
  148. package/src/errors/index.ts +1 -0
  149. package/src/interfaces.ts +1 -1
  150. package/src/specs/NativeAudioAPIModule.ts +5 -15
  151. package/src/specs/NativeAudioAPIModule.web.ts +1 -12
  152. package/src/system/notification/PlaybackNotificationManager.ts +42 -117
  153. package/src/system/notification/RecordingNotificationManager.ios.ts +65 -0
  154. package/src/system/notification/RecordingNotificationManager.ts +33 -183
  155. package/src/system/notification/index.ts +0 -1
  156. package/src/system/notification/types.ts +15 -37
  157. package/src/types.ts +2 -0
  158. package/src/utils/index.ts +3 -2
  159. package/src/utils/paths.ts +11 -0
  160. package/src/web-core/AudioContext.tsx +34 -19
  161. package/src/web-core/BaseAudioContext.tsx +9 -7
  162. package/src/web-system/notification/PlaybackNotificationManager.ts +1 -7
  163. package/src/web-system/notification/RecordingNotificationManager.ts +1 -16
  164. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioPlayer.kt +0 -26
  165. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +0 -26
  166. package/android/src/main/java/com/swmansion/audioapi/system/notification/SimpleNotification.kt +0 -119
  167. package/lib/commonjs/system/notification/SimpleNotificationManager.js +0 -125
  168. package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +0 -1
  169. package/lib/module/system/notification/SimpleNotificationManager.js +0 -121
  170. package/lib/module/system/notification/SimpleNotificationManager.js.map +0 -1
  171. package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +0 -21
  172. package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +0 -1
  173. package/src/system/notification/SimpleNotificationManager.ts +0 -175
@@ -1,133 +1,58 @@
1
- import { Platform } from 'react-native';
2
1
  import { AudioEventEmitter, AudioEventSubscription } from '../../events';
3
2
  import { NativeAudioAPIModule } from '../../specs';
4
3
  import type {
5
- NotificationEvents,
4
+ RecordingNotificationEvent,
6
5
  NotificationManager,
7
- RecordingControlName,
8
6
  RecordingNotificationEventName,
9
7
  RecordingNotificationInfo,
10
8
  } from './types';
11
9
 
12
- /// Manager for recording notifications with controls.
10
+ import { AudioApiError } from '../../errors';
11
+
13
12
  class RecordingNotificationManager
14
13
  implements
15
14
  NotificationManager<
16
- RecordingNotificationInfo,
17
15
  RecordingNotificationInfo,
18
16
  RecordingNotificationEventName
19
17
  >
20
18
  {
21
- private isRegistered_ = false;
22
- private isShown_ = false;
23
-
24
- private notificationKey = 'recording';
19
+ private notificationKey = 'react-native-audio-api-recording';
25
20
  private audioEventEmitter: AudioEventEmitter;
26
- private isIOS = Platform.OS === 'ios';
27
21
 
28
22
  constructor() {
29
23
  this.audioEventEmitter = new AudioEventEmitter(global.AudioEventEmitter);
30
24
  }
31
25
 
32
- /// Register the recording notification (must be called before showing).
33
- async register(): Promise<void> {
34
- if (this.isRegistered_) {
35
- console.warn('RecordingNotification is already registered');
36
- return;
37
- }
38
-
39
- // Recording notifications are only supported on Android
40
- if (this.isIOS) {
41
- this.isRegistered_ = true;
42
- return;
43
- }
44
-
45
- if (!NativeAudioAPIModule) {
46
- throw new Error('NativeAudioAPIModule is not available');
47
- }
48
-
49
- const result = await NativeAudioAPIModule.registerNotification(
50
- 'recording',
51
- this.notificationKey
52
- );
53
-
54
- if (result.error) {
55
- throw new Error(result.error);
56
- }
57
-
58
- this.isRegistered_ = true;
59
- }
60
-
61
- /// Show the notification with initial metadata.
26
+ /**
27
+ * Show the notification with metadata or update if already visible.
28
+ *
29
+ * @param info - The info to be displayed.
30
+ * @returns Promise that resolves after creating notification.
31
+ */
62
32
  async show(info: RecordingNotificationInfo): Promise<void> {
63
- if (!this.isRegistered_) {
64
- throw new Error(
65
- 'RecordingNotification must be registered before showing. Call register() first.'
66
- );
67
- }
68
-
69
- // Recording notifications are only supported on Android
70
- if (this.isIOS) {
71
- this.isShown_ = true;
72
- return;
73
- }
74
-
75
33
  if (!NativeAudioAPIModule) {
76
- throw new Error('NativeAudioAPIModule is not available');
34
+ throw new AudioApiError('NativeAudioAPIModule is not available');
77
35
  }
78
36
 
79
37
  const result = await NativeAudioAPIModule.showNotification(
38
+ 'recording',
80
39
  this.notificationKey,
81
40
  info as Record<string, string | number | boolean | undefined>
82
41
  );
83
42
 
84
43
  if (result.error) {
85
- throw new Error(result.error);
86
- }
87
-
88
- this.isShown_ = true;
89
- }
90
-
91
- /// Update the notification with new metadata or state.
92
- async update(info: RecordingNotificationInfo): Promise<void> {
93
- if (!this.isShown_) {
94
- console.warn('RecordingNotification is not shown. Call show() first.');
95
- return;
96
- }
97
-
98
- // Recording notifications are only supported on Android
99
- if (this.isIOS) {
100
- return;
101
- }
102
-
103
- if (!NativeAudioAPIModule) {
104
- throw new Error('NativeAudioAPIModule is not available');
105
- }
106
-
107
- const result = await NativeAudioAPIModule.updateNotification(
108
- this.notificationKey,
109
- info as Record<string, string | number | boolean | undefined>
110
- );
111
-
112
- if (result.error) {
113
- throw new Error(result.error);
44
+ throw new AudioApiError(result.error);
114
45
  }
115
46
  }
116
47
 
117
- /// Hide the notification (can be shown again later).
48
+ /**
49
+ * Hide the notification.
50
+ *
51
+ * @returns Promise that resolves after hiding notification.
52
+ */
118
53
  async hide(): Promise<void> {
119
- if (!this.isShown_) {
120
- return;
121
- }
122
-
123
- // Recording notifications are only supported on Android
124
- if (this.isIOS) {
125
- this.isShown_ = false;
126
- return;
127
- }
128
-
129
54
  if (!NativeAudioAPIModule) {
130
- throw new Error('NativeAudioAPIModule is not available');
55
+ throw new AudioApiError('NativeAudioAPIModule is not available');
131
56
  }
132
57
 
133
58
  const result = await NativeAudioAPIModule.hideNotification(
@@ -135,80 +60,16 @@ class RecordingNotificationManager
135
60
  );
136
61
 
137
62
  if (result.error) {
138
- throw new Error(result.error);
139
- }
140
-
141
- this.isShown_ = false;
142
- }
143
-
144
- /// Unregister the notification (must register again to use).
145
- async unregister(): Promise<void> {
146
- if (!this.isRegistered_) {
147
- return;
148
- }
149
-
150
- if (this.isShown_) {
151
- await this.hide();
152
- }
153
-
154
- // Recording notifications are only supported on Android
155
- if (this.isIOS) {
156
- this.isRegistered_ = false;
157
- return;
158
- }
159
-
160
- if (!NativeAudioAPIModule) {
161
- throw new Error('NativeAudioAPIModule is not available');
162
- }
163
-
164
- const result = await NativeAudioAPIModule.unregisterNotification(
165
- this.notificationKey
166
- );
167
-
168
- if (result.error) {
169
- throw new Error(result.error);
170
- }
171
-
172
- this.isRegistered_ = false;
173
- }
174
-
175
- /// Enable or disable a specific recording control.
176
- async enableControl(
177
- control: RecordingControlName,
178
- enabled: boolean
179
- ): Promise<void> {
180
- if (!this.isRegistered_) {
181
- console.warn('RecordingNotification is not registered');
182
- return;
183
- }
184
-
185
- // Recording notifications are only supported on Android
186
- if (this.isIOS) {
187
- return;
188
- }
189
-
190
- if (!NativeAudioAPIModule) {
191
- throw new Error('NativeAudioAPIModule is not available');
192
- }
193
-
194
- const params = { control, enabled };
195
- const result = await NativeAudioAPIModule.updateNotification(
196
- this.notificationKey,
197
- params as Record<string, string | number | boolean | undefined>
198
- );
199
-
200
- if (result.error) {
201
- throw new Error(result.error);
63
+ throw new AudioApiError(result.error);
202
64
  }
203
65
  }
204
66
 
205
- /// Check if the notification is currently active.
67
+ /**
68
+ * Check if the notification is currently active.
69
+ *
70
+ * @returns Promise that resolves to whether notification is active.
71
+ */
206
72
  async isActive(): Promise<boolean> {
207
- // Recording notifications are only supported on Android
208
- if (this.isIOS) {
209
- return this.isShown_;
210
- }
211
-
212
73
  if (!NativeAudioAPIModule) {
213
74
  return false;
214
75
  }
@@ -218,30 +79,19 @@ class RecordingNotificationManager
218
79
  );
219
80
  }
220
81
 
221
- isRegistered(): boolean {
222
- return this.isRegistered_;
223
- }
224
-
225
- /// Add an event listener for notification actions.
82
+ /**
83
+ * Add an event listener for notification actions.
84
+ *
85
+ * @param eventName - The event name to listen for.
86
+ * @param callback - The callback to invoke on event.
87
+ * @returns Class that represents the subscription.
88
+ */
226
89
  addEventListener<T extends RecordingNotificationEventName>(
227
90
  eventName: T,
228
- callback: (event: NotificationEvents[T]) => void
91
+ callback: (event: RecordingNotificationEvent[T]) => void
229
92
  ): AudioEventSubscription {
230
- // Recording notifications are only supported on Android
231
- if (this.isIOS) {
232
- // Return a dummy subscription for iOS
233
- return {
234
- remove: () => {},
235
- } as unknown as AudioEventSubscription;
236
- }
237
-
238
93
  return this.audioEventEmitter.addAudioEventListener(eventName, callback);
239
94
  }
240
-
241
- /** Remove an event listener. */
242
- removeEventListener(subscription: AudioEventSubscription): void {
243
- subscription.remove();
244
- }
245
95
  }
246
96
 
247
97
  export default new RecordingNotificationManager();
@@ -1,4 +1,3 @@
1
1
  export { default as PlaybackNotificationManager } from './PlaybackNotificationManager';
2
2
  export { default as RecordingNotificationManager } from './RecordingNotificationManager';
3
- export { default as SimpleNotificationManager } from './SimpleNotificationManager';
4
3
  export * from './types';
@@ -5,24 +5,15 @@ import { EventEmptyType, EventTypeWithValue } from '../../events/types';
5
5
  /// Provides a consistent API for managing notification lifecycle and events.
6
6
  export interface NotificationManager<
7
7
  TShowOptions,
8
- TUpdateOptions,
9
8
  TEventName extends NotificationEventName,
10
9
  > {
11
- /// Register the notification (must be called before showing).
12
- register(): Promise<void>;
13
-
14
- /// Show the notification with initial options.
10
+ /// Show the notification with options or update if already visible.
11
+ /// Automatically creates the notification instance on first call.
15
12
  show(options: TShowOptions): Promise<void>;
16
13
 
17
- /// Update the notification with new options.
18
- update(options: TUpdateOptions): Promise<void>;
19
-
20
- /// Hide the notification (can be shown again later).
14
+ /// Hide the notification.
21
15
  hide(): Promise<void>;
22
16
 
23
- /// Unregister the notification (must register again to use).
24
- unregister(): Promise<void>;
25
-
26
17
  /// Check if the notification is currently active.
27
18
  isActive(): Promise<boolean>;
28
19
 
@@ -31,9 +22,6 @@ export interface NotificationManager<
31
22
  eventName: T,
32
23
  callback: NotificationCallback<T>
33
24
  ): AudioEventSubscription | undefined;
34
-
35
- /// Remove an event listener.
36
- removeEventListener(subscription: AudioEventSubscription): void;
37
25
  }
38
26
 
39
27
  /// Metadata and state information for playback notifications.
@@ -71,28 +59,24 @@ interface PlaybackNotificationEvent {
71
59
  playbackNotificationDismissed: EventEmptyType;
72
60
  }
73
61
 
74
- export type PlaybackNotificationEventName = keyof PlaybackNotificationEvent;
75
-
76
- /// Metadata and state information for recording notifications.
77
62
  export interface RecordingNotificationInfo {
78
63
  title?: string;
79
- description?: string;
80
- artwork?: string | { uri: string };
81
- state?: 'recording' | 'stopped';
82
- control?: RecordingControlName;
83
- enabled?: boolean;
64
+ contentText?: string;
65
+ paused?: boolean;
66
+ smallIconResourceName?: string;
67
+ largeIconResourceName?: string;
68
+ pauseIconResourceName?: string;
69
+ resumeIconResourceName?: string;
70
+ color?: number;
84
71
  }
85
72
 
86
- /// Available recording control actions.
87
- export type RecordingControlName = 'start' | 'stop';
88
-
89
- /// Event names for recording notification actions.
90
- interface RecordingNotificationEvent {
91
- recordingNotificationStart: EventEmptyType;
92
- recordingNotificationStop: EventEmptyType;
93
- recordingNotificationDismissed: EventEmptyType;
73
+ export interface RecordingNotificationEvent {
74
+ recordingNotificationPause: EventEmptyType;
75
+ recordingNotificationResume: EventEmptyType;
94
76
  }
95
77
 
78
+ export type PlaybackNotificationEventName = keyof PlaybackNotificationEvent;
79
+
96
80
  export type RecordingNotificationEventName = keyof RecordingNotificationEvent;
97
81
 
98
82
  export type NotificationEvents = PlaybackNotificationEvent &
@@ -103,9 +87,3 @@ export type NotificationEventName = keyof NotificationEvents;
103
87
  export type NotificationCallback<Name extends NotificationEventName> = (
104
88
  event: NotificationEvents[Name]
105
89
  ) => void;
106
-
107
- /// Options for a simple notification with title and text.
108
- export interface SimpleNotificationOptions {
109
- title?: string;
110
- text?: string;
111
- }
package/src/types.ts CHANGED
@@ -149,3 +149,5 @@ export interface IIRFilterNodeOptions {
149
149
  feedforward: number[];
150
150
  feedback: number[];
151
151
  }
152
+
153
+ export type DecodeDataInput = number | string | ArrayBuffer;
@@ -1,14 +1,15 @@
1
1
  import AudioAPIModule from '../AudioAPIModule';
2
+ import { AudioApiError } from '../errors';
2
3
 
3
4
  export function assertWorkletsEnabled() {
4
5
  if (!AudioAPIModule.areWorkletsAvailable) {
5
- throw new Error(
6
+ throw new AudioApiError(
6
7
  '[react-native-audio-api]: Worklets are not available. Please install react-native-worklets to use this feature.'
7
8
  );
8
9
  }
9
10
 
10
11
  if (!AudioAPIModule.isWorkletsVersionSupported) {
11
- throw new Error(
12
+ throw new AudioApiError(
12
13
  `[react-native-audio-api]: Worklets version ${AudioAPIModule.workletsVersion} is not supported.
13
14
  Please install react-native-worklets of one of the following versions: [${AudioAPIModule.supportedWorkletsVersion.join(', ')}] to use this feature.`
14
15
  );
@@ -0,0 +1,11 @@
1
+ export function isRemoteSource(url: string): boolean {
2
+ return url.startsWith('http://') || url.startsWith('https://');
3
+ }
4
+
5
+ export function isBase64Source(data: string): boolean {
6
+ return data.startsWith('data:audio/') && data.includes(';base64,');
7
+ }
8
+
9
+ export function isDataBlobString(data: string): boolean {
10
+ return data.startsWith('blob:');
11
+ }
@@ -1,28 +1,29 @@
1
+ import { InvalidAccessError, NotSupportedError } from '../errors';
1
2
  import {
2
- ContextState,
3
- PeriodicWaveConstraints,
4
- AudioContextOptions,
5
3
  AudioBufferBaseSourceNodeOptions,
4
+ AudioContextOptions,
5
+ ContextState,
6
+ DecodeDataInput,
6
7
  IIRFilterNodeOptions,
8
+ PeriodicWaveConstraints,
7
9
  } from '../types';
8
- import { InvalidAccessError, NotSupportedError } from '../errors';
9
- import BaseAudioContext from './BaseAudioContext';
10
10
  import AnalyserNode from './AnalyserNode';
11
- import AudioDestinationNode from './AudioDestinationNode';
12
11
  import AudioBuffer from './AudioBuffer';
13
12
  import AudioBufferSourceNode from './AudioBufferSourceNode';
13
+ import AudioDestinationNode from './AudioDestinationNode';
14
+ import BaseAudioContext from './BaseAudioContext';
14
15
  import BiquadFilterNode from './BiquadFilterNode';
15
- import IIRFilterNode from './IIRFilterNode';
16
+ import ConvolverNode from './ConvolverNode';
17
+ import { ConvolverNodeOptions } from './ConvolverNodeOptions';
18
+ import DelayNode from './DelayNode';
16
19
  import GainNode from './GainNode';
20
+ import IIRFilterNode from './IIRFilterNode';
17
21
  import OscillatorNode from './OscillatorNode';
18
22
  import PeriodicWave from './PeriodicWave';
19
23
  import StereoPannerNode from './StereoPannerNode';
20
- import ConvolverNode from './ConvolverNode';
21
- import DelayNode from './DelayNode';
22
- import { ConvolverNodeOptions } from './ConvolverNodeOptions';
23
24
 
24
- import { globalWasmPromise, globalTag } from './custom/LoadCustomWasm';
25
25
  import ConstantSourceNode from './ConstantSourceNode';
26
+ import { globalTag, globalWasmPromise } from './custom/LoadCustomWasm';
26
27
  import WaveShaperNode from './WaveShaperNode';
27
28
 
28
29
  export default class AudioContext implements BaseAudioContext {
@@ -180,16 +181,30 @@ export default class AudioContext implements BaseAudioContext {
180
181
  return new WaveShaperNode(this, this.context.createWaveShaper());
181
182
  }
182
183
 
183
- async decodeAudioDataSource(source: string): Promise<AudioBuffer> {
184
- const arrayBuffer = await fetch(source).then((response) =>
185
- response.arrayBuffer()
186
- );
184
+ async decodeAudioData(
185
+ source: DecodeDataInput,
186
+ fetchOptions?: RequestInit
187
+ ): Promise<AudioBuffer> {
188
+ if (source instanceof ArrayBuffer) {
189
+ const decodedData = await this.context.decodeAudioData(source);
190
+ return new AudioBuffer(decodedData);
191
+ }
187
192
 
188
- return this.decodeAudioData(arrayBuffer);
189
- }
193
+ if (typeof source === 'string') {
194
+ const response = await fetch(source, fetchOptions);
195
+
196
+ if (!response.ok) {
197
+ throw new InvalidAccessError(
198
+ `Failed to fetch audio data from the provided source: ${source}`
199
+ );
200
+ }
201
+
202
+ const arrayBuffer = await response.arrayBuffer();
203
+ const decodedData = await this.context.decodeAudioData(arrayBuffer);
204
+ return new AudioBuffer(decodedData);
205
+ }
190
206
 
191
- async decodeAudioData(arrayBuffer: ArrayBuffer): Promise<AudioBuffer> {
192
- return new AudioBuffer(await this.context.decodeAudioData(arrayBuffer));
207
+ throw new TypeError('Unsupported source for decodeAudioData: ' + source);
193
208
  }
194
209
 
195
210
  async close(): Promise<void> {
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  ContextState,
3
- PeriodicWaveConstraints,
4
3
  IIRFilterNodeOptions,
4
+ PeriodicWaveConstraints,
5
5
  } from '../types';
6
6
  import AnalyserNode from './AnalyserNode';
7
- import AudioDestinationNode from './AudioDestinationNode';
8
7
  import AudioBuffer from './AudioBuffer';
9
8
  import AudioBufferSourceNode from './AudioBufferSourceNode';
9
+ import AudioDestinationNode from './AudioDestinationNode';
10
10
  import BiquadFilterNode from './BiquadFilterNode';
11
+ import ConstantSourceNode from './ConstantSourceNode';
12
+ import ConvolverNode from './ConvolverNode';
11
13
  import DelayNode from './DelayNode';
12
- import IIRFilterNode from './IIRFilterNode';
13
14
  import GainNode from './GainNode';
15
+ import IIRFilterNode from './IIRFilterNode';
14
16
  import OscillatorNode from './OscillatorNode';
15
17
  import PeriodicWave from './PeriodicWave';
16
18
  import StereoPannerNode from './StereoPannerNode';
17
- import ConstantSourceNode from './ConstantSourceNode';
18
- import ConvolverNode from './ConvolverNode';
19
19
  import WaveShaperNode from './WaveShaperNode';
20
20
 
21
21
  export default interface BaseAudioContext {
@@ -47,6 +47,8 @@ export default interface BaseAudioContext {
47
47
  ): PeriodicWave;
48
48
  createAnalyser(): AnalyserNode;
49
49
  createWaveShaper(): WaveShaperNode;
50
- decodeAudioDataSource(source: string): Promise<AudioBuffer>;
51
- decodeAudioData(arrayBuffer: ArrayBuffer): Promise<AudioBuffer>;
50
+ decodeAudioData(
51
+ arrayBuffer: ArrayBuffer,
52
+ fetchOptions?: RequestInit
53
+ ): Promise<AudioBuffer>;
52
54
  }
@@ -14,11 +14,7 @@ import type {
14
14
  /// Mock Manager for playback notifications. Does nothing.
15
15
  class PlaybackNotificationManager
16
16
  implements
17
- NotificationManager<
18
- PlaybackNotificationInfo,
19
- PlaybackNotificationInfo,
20
- PlaybackNotificationEventName
21
- >
17
+ NotificationManager<PlaybackNotificationInfo, PlaybackNotificationEventName>
22
18
  {
23
19
  private isRegistered_ = false;
24
20
  private isShown_ = false;
@@ -57,8 +53,6 @@ class PlaybackNotificationManager
57
53
  remove: () => {},
58
54
  } as unknown as AudioEventSubscription;
59
55
  }
60
-
61
- removeEventListener(subscription: AudioEventSubscription): void {}
62
56
  }
63
57
 
64
58
  export default new PlaybackNotificationManager();
@@ -6,16 +6,14 @@ import type { AudioEventSubscription } from '../../events';
6
6
  import type {
7
7
  NotificationEvents,
8
8
  NotificationManager,
9
- RecordingControlName,
10
9
  RecordingNotificationEventName,
11
10
  RecordingNotificationInfo,
12
11
  } from '../../system';
13
12
 
14
- /// Mock Manager for recording notifications. Does nothing.
13
+ /// Mock Manager for playback notifications. Does nothing.
15
14
  class RecordingNotificationManager
16
15
  implements
17
16
  NotificationManager<
18
- RecordingNotificationInfo,
19
17
  RecordingNotificationInfo,
20
18
  RecordingNotificationEventName
21
19
  >
@@ -25,21 +23,10 @@ class RecordingNotificationManager
25
23
 
26
24
  constructor() {}
27
25
 
28
- async register(): Promise<void> {}
29
-
30
26
  async show(info: RecordingNotificationInfo): Promise<void> {}
31
27
 
32
- async update(info: RecordingNotificationInfo): Promise<void> {}
33
-
34
28
  async hide(): Promise<void> {}
35
29
 
36
- async unregister(): Promise<void> {}
37
-
38
- async enableControl(
39
- control: RecordingControlName,
40
- enabled: boolean
41
- ): Promise<void> {}
42
-
43
30
  async isActive(): Promise<boolean> {
44
31
  return this.isShown_;
45
32
  }
@@ -57,8 +44,6 @@ class RecordingNotificationManager
57
44
  remove: () => {},
58
45
  } as unknown as AudioEventSubscription;
59
46
  }
60
-
61
- removeEventListener(subscription: AudioEventSubscription): void {}
62
47
  }
63
48
 
64
49
  export default new RecordingNotificationManager();
@@ -1,26 +0,0 @@
1
- package com.swmansion.audioapi.core
2
-
3
- import com.facebook.common.internal.DoNotStrip
4
- import com.swmansion.audioapi.system.ForegroundServiceManager
5
- import java.util.UUID
6
-
7
- @DoNotStrip
8
- class NativeAudioPlayer {
9
- private var playerId: String? = null
10
-
11
- @DoNotStrip
12
- fun start() {
13
- if (playerId == null) {
14
- playerId = UUID.randomUUID().toString()
15
- ForegroundServiceManager.subscribe("player_$playerId")
16
- }
17
- }
18
-
19
- @DoNotStrip
20
- fun stop() {
21
- playerId?.let {
22
- ForegroundServiceManager.unsubscribe("player_$it")
23
- playerId = null
24
- }
25
- }
26
- }
@@ -1,26 +0,0 @@
1
- package com.swmansion.audioapi.core
2
-
3
- import com.facebook.common.internal.DoNotStrip
4
- import com.swmansion.audioapi.system.ForegroundServiceManager
5
- import java.util.UUID
6
-
7
- @DoNotStrip
8
- class NativeAudioRecorder {
9
- private var recorderId: String? = null
10
-
11
- @DoNotStrip
12
- fun start() {
13
- if (recorderId == null) {
14
- recorderId = UUID.randomUUID().toString()
15
- ForegroundServiceManager.subscribe("recorder_$recorderId")
16
- }
17
- }
18
-
19
- @DoNotStrip
20
- fun stop() {
21
- recorderId?.let {
22
- ForegroundServiceManager.unsubscribe("recorder_$it")
23
- recorderId = null
24
- }
25
- }
26
- }