audio-channel-queue 1.5.0 → 1.7.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 +323 -96
- package/dist/core.d.ts +27 -9
- package/dist/core.js +132 -29
- package/dist/errors.d.ts +137 -0
- package/dist/errors.js +461 -0
- package/dist/events.d.ts +23 -1
- package/dist/events.js +50 -2
- package/dist/index.d.ts +9 -19
- package/dist/index.js +45 -25
- package/dist/info.d.ts +47 -2
- package/dist/info.js +126 -7
- package/dist/pause.d.ts +87 -0
- package/dist/pause.js +186 -0
- package/dist/types.d.ts +113 -12
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +24 -4
- package/dist/volume.d.ts +98 -0
- package/dist/volume.js +305 -0
- package/package.json +4 -1
- package/src/core.ts +144 -27
- package/src/errors.ts +480 -0
- package/src/events.ts +242 -188
- package/src/index.ts +91 -66
- package/src/info.ts +386 -261
- package/src/pause.ts +190 -0
- package/src/types.ts +235 -126
- package/src/utils.ts +133 -108
- package/src/volume.ts +331 -0
package/src/info.ts
CHANGED
|
@@ -1,262 +1,387 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AudioInfo,
|
|
7
|
-
QueueSnapshot,
|
|
8
|
-
ProgressCallback,
|
|
9
|
-
QueueChangeCallback,
|
|
10
|
-
AudioStartCallback,
|
|
11
|
-
AudioCompleteCallback,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
channel.progressCallbacks.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Audio information and progress tracking functions for the audio-channel-queue package
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AudioInfo,
|
|
7
|
+
QueueSnapshot,
|
|
8
|
+
ProgressCallback,
|
|
9
|
+
QueueChangeCallback,
|
|
10
|
+
AudioStartCallback,
|
|
11
|
+
AudioCompleteCallback,
|
|
12
|
+
AudioPauseCallback,
|
|
13
|
+
AudioResumeCallback,
|
|
14
|
+
ExtendedAudioQueueChannel
|
|
15
|
+
} from './types';
|
|
16
|
+
import { getAudioInfoFromElement, createQueueSnapshot } from './utils';
|
|
17
|
+
import { setupProgressTracking, cleanupProgressTracking } from './events';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Global array to store audio channels with their queues and callback management
|
|
21
|
+
* Each channel maintains its own audio queue and event callback sets
|
|
22
|
+
*/
|
|
23
|
+
export const audioChannels: ExtendedAudioQueueChannel[] = [];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets current audio information for a specific channel
|
|
27
|
+
* @param channelNumber - The channel number (defaults to 0)
|
|
28
|
+
* @returns AudioInfo object or null if no audio is playing
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const info = getCurrentAudioInfo(0);
|
|
32
|
+
* if (info) {
|
|
33
|
+
* console.log(`Currently playing: ${info.fileName}`);
|
|
34
|
+
* console.log(`Progress: ${(info.progress * 100).toFixed(1)}%`);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const getCurrentAudioInfo = (channelNumber: number = 0): AudioInfo | null => {
|
|
39
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
40
|
+
if (!channel || channel.queue.length === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const currentAudio: HTMLAudioElement = channel.queue[0];
|
|
45
|
+
return getAudioInfoFromElement(currentAudio, channelNumber, audioChannels);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets audio information for all channels
|
|
50
|
+
* @returns Array of AudioInfo objects (null for channels with no audio)
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const allInfo = getAllChannelsInfo();
|
|
54
|
+
* allInfo.forEach((info, channel) => {
|
|
55
|
+
* if (info) {
|
|
56
|
+
* console.log(`Channel ${channel}: ${info.fileName}`);
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export const getAllChannelsInfo = (): (AudioInfo | null)[] => {
|
|
62
|
+
const allChannelsInfo: (AudioInfo | null)[] = [];
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < audioChannels.length; i++) {
|
|
65
|
+
allChannelsInfo.push(getCurrentAudioInfo(i));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return allChannelsInfo;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets a complete snapshot of the queue state for a specific channel
|
|
73
|
+
* @param channelNumber - The channel number
|
|
74
|
+
* @returns QueueSnapshot object or null if channel doesn't exist
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const snapshot = getQueueSnapshot(0);
|
|
78
|
+
* if (snapshot) {
|
|
79
|
+
* console.log(`Queue has ${snapshot.totalItems} items`);
|
|
80
|
+
* console.log(`Currently playing: ${snapshot.items[0]?.fileName}`);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export const getQueueSnapshot = (channelNumber: number): QueueSnapshot | null => {
|
|
85
|
+
return createQueueSnapshot(channelNumber, audioChannels);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Subscribes to real-time progress updates for a specific channel
|
|
90
|
+
* @param channelNumber - The channel number
|
|
91
|
+
* @param callback - Function to call with audio info updates
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* onAudioProgress(0, (info) => {
|
|
95
|
+
* updateProgressBar(info.progress);
|
|
96
|
+
* updateTimeDisplay(info.currentTime, info.duration);
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const onAudioProgress = (channelNumber: number, callback: ProgressCallback): void => {
|
|
101
|
+
if (!audioChannels[channelNumber]) {
|
|
102
|
+
audioChannels[channelNumber] = {
|
|
103
|
+
audioCompleteCallbacks: new Set(),
|
|
104
|
+
audioErrorCallbacks: new Set(),
|
|
105
|
+
audioPauseCallbacks: new Set(),
|
|
106
|
+
audioResumeCallbacks: new Set(),
|
|
107
|
+
audioStartCallbacks: new Set(),
|
|
108
|
+
isPaused: false,
|
|
109
|
+
progressCallbacks: new Map(),
|
|
110
|
+
queue: [],
|
|
111
|
+
queueChangeCallbacks: new Set(),
|
|
112
|
+
volume: 1.0
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
117
|
+
if (!channel.progressCallbacks) {
|
|
118
|
+
channel.progressCallbacks = new Map();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Add callback for current audio if exists
|
|
122
|
+
if (channel.queue.length > 0) {
|
|
123
|
+
const currentAudio: HTMLAudioElement = channel.queue[0];
|
|
124
|
+
if (!channel.progressCallbacks.has(currentAudio)) {
|
|
125
|
+
channel.progressCallbacks.set(currentAudio, new Set());
|
|
126
|
+
}
|
|
127
|
+
channel.progressCallbacks.get(currentAudio)!.add(callback);
|
|
128
|
+
|
|
129
|
+
// Set up tracking if not already done
|
|
130
|
+
setupProgressTracking(currentAudio, channelNumber, audioChannels);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Store callback for future audio elements in this channel
|
|
134
|
+
if (!channel.progressCallbacks.has(null as any)) {
|
|
135
|
+
channel.progressCallbacks.set(null as any, new Set());
|
|
136
|
+
}
|
|
137
|
+
channel.progressCallbacks.get(null as any)!.add(callback);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Removes progress listeners for a specific channel
|
|
142
|
+
* @param channelNumber - The channel number
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* offAudioProgress(0); // Stop receiving progress updates for channel 0
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export const offAudioProgress = (channelNumber: number): void => {
|
|
149
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
150
|
+
if (!channel || !channel.progressCallbacks) return;
|
|
151
|
+
|
|
152
|
+
// Clean up event listeners for current audio if exists
|
|
153
|
+
if (channel.queue.length > 0) {
|
|
154
|
+
const currentAudio: HTMLAudioElement = channel.queue[0];
|
|
155
|
+
cleanupProgressTracking(currentAudio, channelNumber, audioChannels);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Clear all callbacks for this channel
|
|
159
|
+
channel.progressCallbacks.clear();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Subscribes to queue change events for a specific channel
|
|
164
|
+
* @param channelNumber - The channel number to monitor
|
|
165
|
+
* @param callback - Function to call when queue changes
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* onQueueChange(0, (snapshot) => {
|
|
169
|
+
* updateQueueDisplay(snapshot.items);
|
|
170
|
+
* updateQueueCount(snapshot.totalItems);
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export const onQueueChange = (channelNumber: number, callback: QueueChangeCallback): void => {
|
|
175
|
+
if (!audioChannels[channelNumber]) {
|
|
176
|
+
audioChannels[channelNumber] = {
|
|
177
|
+
audioCompleteCallbacks: new Set(),
|
|
178
|
+
audioErrorCallbacks: new Set(),
|
|
179
|
+
audioPauseCallbacks: new Set(),
|
|
180
|
+
audioResumeCallbacks: new Set(),
|
|
181
|
+
audioStartCallbacks: new Set(),
|
|
182
|
+
isPaused: false,
|
|
183
|
+
progressCallbacks: new Map(),
|
|
184
|
+
queue: [],
|
|
185
|
+
queueChangeCallbacks: new Set(),
|
|
186
|
+
volume: 1.0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
191
|
+
if (!channel.queueChangeCallbacks) {
|
|
192
|
+
channel.queueChangeCallbacks = new Set();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
channel.queueChangeCallbacks.add(callback);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Removes queue change listeners for a specific channel
|
|
200
|
+
* @param channelNumber - The channel number
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* offQueueChange(0); // Stop receiving queue change notifications for channel 0
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export const offQueueChange = (channelNumber: number): void => {
|
|
207
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
208
|
+
if (!channel || !channel.queueChangeCallbacks) return;
|
|
209
|
+
|
|
210
|
+
channel.queueChangeCallbacks.clear();
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Subscribes to audio start events for a specific channel
|
|
215
|
+
* @param channelNumber - The channel number to monitor
|
|
216
|
+
* @param callback - Function to call when audio starts playing
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* onAudioStart(0, (info) => {
|
|
220
|
+
* showNowPlaying(info.fileName);
|
|
221
|
+
* setTotalDuration(info.duration);
|
|
222
|
+
* });
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export const onAudioStart = (channelNumber: number, callback: AudioStartCallback): void => {
|
|
226
|
+
if (!audioChannels[channelNumber]) {
|
|
227
|
+
audioChannels[channelNumber] = {
|
|
228
|
+
audioCompleteCallbacks: new Set(),
|
|
229
|
+
audioErrorCallbacks: new Set(),
|
|
230
|
+
audioPauseCallbacks: new Set(),
|
|
231
|
+
audioResumeCallbacks: new Set(),
|
|
232
|
+
audioStartCallbacks: new Set(),
|
|
233
|
+
isPaused: false,
|
|
234
|
+
progressCallbacks: new Map(),
|
|
235
|
+
queue: [],
|
|
236
|
+
queueChangeCallbacks: new Set(),
|
|
237
|
+
volume: 1.0
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
242
|
+
if (!channel.audioStartCallbacks) {
|
|
243
|
+
channel.audioStartCallbacks = new Set();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
channel.audioStartCallbacks.add(callback);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Subscribes to audio complete events for a specific channel
|
|
251
|
+
* @param channelNumber - The channel number to monitor
|
|
252
|
+
* @param callback - Function to call when audio completes
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* onAudioComplete(0, (info) => {
|
|
256
|
+
* logPlaybackComplete(info.fileName);
|
|
257
|
+
* if (info.remainingInQueue === 0) {
|
|
258
|
+
* showQueueComplete();
|
|
259
|
+
* }
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export const onAudioComplete = (channelNumber: number, callback: AudioCompleteCallback): void => {
|
|
264
|
+
if (!audioChannels[channelNumber]) {
|
|
265
|
+
audioChannels[channelNumber] = {
|
|
266
|
+
audioCompleteCallbacks: new Set(),
|
|
267
|
+
audioErrorCallbacks: new Set(),
|
|
268
|
+
audioPauseCallbacks: new Set(),
|
|
269
|
+
audioResumeCallbacks: new Set(),
|
|
270
|
+
audioStartCallbacks: new Set(),
|
|
271
|
+
isPaused: false,
|
|
272
|
+
progressCallbacks: new Map(),
|
|
273
|
+
queue: [],
|
|
274
|
+
queueChangeCallbacks: new Set(),
|
|
275
|
+
volume: 1.0
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
280
|
+
if (!channel.audioCompleteCallbacks) {
|
|
281
|
+
channel.audioCompleteCallbacks = new Set();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
channel.audioCompleteCallbacks.add(callback);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Subscribes to audio pause events for a specific channel
|
|
289
|
+
* @param channelNumber - The channel number to monitor
|
|
290
|
+
* @param callback - Function to call when audio is paused
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* onAudioPause(0, (channelNumber, info) => {
|
|
294
|
+
* showPauseIndicator();
|
|
295
|
+
* logPauseEvent(info.fileName, info.currentTime);
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export const onAudioPause = (channelNumber: number, callback: AudioPauseCallback): void => {
|
|
300
|
+
if (!audioChannels[channelNumber]) {
|
|
301
|
+
audioChannels[channelNumber] = {
|
|
302
|
+
audioCompleteCallbacks: new Set(),
|
|
303
|
+
audioErrorCallbacks: new Set(),
|
|
304
|
+
audioPauseCallbacks: new Set(),
|
|
305
|
+
audioResumeCallbacks: new Set(),
|
|
306
|
+
audioStartCallbacks: new Set(),
|
|
307
|
+
isPaused: false,
|
|
308
|
+
progressCallbacks: new Map(),
|
|
309
|
+
queue: [],
|
|
310
|
+
queueChangeCallbacks: new Set(),
|
|
311
|
+
volume: 1.0
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
316
|
+
if (!channel.audioPauseCallbacks) {
|
|
317
|
+
channel.audioPauseCallbacks = new Set();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
channel.audioPauseCallbacks.add(callback);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Subscribes to audio resume events for a specific channel
|
|
325
|
+
* @param channelNumber - The channel number to monitor
|
|
326
|
+
* @param callback - Function to call when audio is resumed
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* onAudioResume(0, (channelNumber, info) => {
|
|
330
|
+
* hidePauseIndicator();
|
|
331
|
+
* logResumeEvent(info.fileName, info.currentTime);
|
|
332
|
+
* });
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
export const onAudioResume = (channelNumber: number, callback: AudioResumeCallback): void => {
|
|
336
|
+
if (!audioChannels[channelNumber]) {
|
|
337
|
+
audioChannels[channelNumber] = {
|
|
338
|
+
audioCompleteCallbacks: new Set(),
|
|
339
|
+
audioErrorCallbacks: new Set(),
|
|
340
|
+
audioPauseCallbacks: new Set(),
|
|
341
|
+
audioResumeCallbacks: new Set(),
|
|
342
|
+
audioStartCallbacks: new Set(),
|
|
343
|
+
isPaused: false,
|
|
344
|
+
progressCallbacks: new Map(),
|
|
345
|
+
queue: [],
|
|
346
|
+
queueChangeCallbacks: new Set(),
|
|
347
|
+
volume: 1.0
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
352
|
+
if (!channel.audioResumeCallbacks) {
|
|
353
|
+
channel.audioResumeCallbacks = new Set();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
channel.audioResumeCallbacks.add(callback);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Removes pause event listeners for a specific channel
|
|
361
|
+
* @param channelNumber - The channel number
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* offAudioPause(0); // Stop receiving pause notifications for channel 0
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
export const offAudioPause = (channelNumber: number): void => {
|
|
368
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
369
|
+
if (!channel || !channel.audioPauseCallbacks) return;
|
|
370
|
+
|
|
371
|
+
channel.audioPauseCallbacks.clear();
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Removes resume event listeners for a specific channel
|
|
376
|
+
* @param channelNumber - The channel number
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* offAudioResume(0); // Stop receiving resume notifications for channel 0
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
export const offAudioResume = (channelNumber: number): void => {
|
|
383
|
+
const channel: ExtendedAudioQueueChannel = audioChannels[channelNumber];
|
|
384
|
+
if (!channel || !channel.audioResumeCallbacks) return;
|
|
385
|
+
|
|
386
|
+
channel.audioResumeCallbacks.clear();
|
|
262
387
|
};
|