@octane-xplat/audio 0.18.0 → 0.20.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 +2 -66
- package/package.json +103 -98
- package/platforms/android/audio.aar +0 -0
- package/platforms/android/java/com/xplat/audio/AudioBridge.java +16 -8
- package/platforms/android/java/com/xplat/audio/AudioPlaybackService.java +63 -10
- package/platforms/macos/include/XplatAudioPlayer.h +3 -0
- package/platforms/macos/src/XplatAudioPlayer.m +27 -1
- package/src/audio.android.ts +193 -136
- package/src/audio.ios.ts +495 -377
- package/src/audio.macos.ts +372 -267
- package/src/audio.ts +8 -7
- package/src/audio.web.ts +306 -179
- package/src/audio.windows.ts +7 -0
- package/src/queue.ts +15 -0
- package/src/settings.ts +8 -0
- package/src/types.ts +89 -27
- package/types/generated/.tsrx-typegen-manifest.json +12 -0
- package/types/generated/audio.android.d.ts +3 -0
- package/types/generated/audio.d.ts +3 -0
- package/types/generated/audio.ios.d.ts +3 -0
- package/types/generated/index.d.ts +2 -0
- package/types/generated/queue.d.ts +3 -0
- package/types/generated/settings.d.ts +2 -0
- package/types/generated/types.d.ts +90 -0
- package/LICENSE +0 -21
- package/types/index.d.ts +0 -1
- package/types/types.d.ts +0 -36
package/src/audio.macos.ts
CHANGED
|
@@ -1,278 +1,383 @@
|
|
|
1
|
+
import { copyQueue } from './queue'
|
|
2
|
+
import { bounded } from './settings'
|
|
1
3
|
import type { AudioPlayer, AudioSnapshot, Track } from './types'
|
|
2
4
|
|
|
3
5
|
type NativeSnapshot = Pick<AudioSnapshot, 'state' | 'currentTime' | 'duration'> & { error?: string }
|
|
4
6
|
type NativePlayer = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
setPlaybackRate(rate: number): void
|
|
8
|
+
setVolume(volume: number): void
|
|
9
|
+
setMuted(muted: boolean): void
|
|
10
|
+
setSource(source: string): void
|
|
11
|
+
play(): void
|
|
12
|
+
pause(): void
|
|
13
|
+
seekSeconds(seconds: number): void
|
|
14
|
+
snapshot(): string
|
|
15
|
+
clear(): void
|
|
16
|
+
dispose(): void
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
declare const XplatAudioPlayer: { new: () => NativePlayer }
|
|
15
20
|
|
|
16
21
|
/** The CLI loads the package's AVFoundation leaf before evaluating the app. */
|
|
22
|
+
/** Create an independent player on web/iOS/macOS; Android owns one app playback service. */
|
|
17
23
|
export const createAudioPlayer = (): AudioPlayer => {
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
24
|
+
const native = typeof XplatAudioPlayer === 'undefined' ? undefined : XplatAudioPlayer.new()
|
|
25
|
+
const listeners = new Set<(snapshot: AudioSnapshot) => void>()
|
|
26
|
+
let queue: Track[] = []
|
|
27
|
+
let index = -1
|
|
28
|
+
let disposed = false
|
|
29
|
+
let playbackRate = 1
|
|
30
|
+
let volume = 1
|
|
31
|
+
let muted = false
|
|
32
|
+
let queueComplete = true
|
|
33
|
+
let waitingToResume = false
|
|
34
|
+
let generation = 0
|
|
35
|
+
let playRequest = 0
|
|
36
|
+
let timer: ReturnType<typeof setInterval> | undefined
|
|
37
|
+
let pending: { promise: Promise<void>; resolve(): void; reject(error: Error): void } | undefined
|
|
38
|
+
let value: Omit<AudioSnapshot, 'playbackRate' | 'volume' | 'muted' | 'queueComplete'> = {
|
|
39
|
+
state: 'idle',
|
|
40
|
+
currentTime: 0,
|
|
41
|
+
duration: 0,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const assertActive = () => {
|
|
45
|
+
if (disposed) {
|
|
46
|
+
throw new Error('AudioPlayer is disposed')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const snapshot = () => ({
|
|
51
|
+
...value,
|
|
52
|
+
playbackRate,
|
|
53
|
+
volume,
|
|
54
|
+
muted,
|
|
55
|
+
queueComplete,
|
|
56
|
+
track: queue[index] ? { ...queue[index] } : undefined,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const emit = () => {
|
|
60
|
+
const currentGeneration = generation
|
|
61
|
+
const current = snapshot()
|
|
62
|
+
|
|
63
|
+
for (const listener of listeners) {
|
|
64
|
+
if (disposed || currentGeneration !== generation) {
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
listener(current)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const stopTimer = () => {
|
|
73
|
+
if (timer !== undefined) {
|
|
74
|
+
clearInterval(timer)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
timer = undefined
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const fail = (cause: unknown) => {
|
|
81
|
+
const error = cause instanceof Error ? cause : new Error(String(cause))
|
|
82
|
+
|
|
83
|
+
// Retain the original failure even when cleanup itself fails.
|
|
84
|
+
try {
|
|
85
|
+
native?.clear()
|
|
86
|
+
} catch {
|
|
87
|
+
/* The owned bridge has already failed. */
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
value = { ...value, state: 'error', error }
|
|
91
|
+
pending?.reject(error)
|
|
92
|
+
pending = undefined
|
|
93
|
+
stopTimer()
|
|
94
|
+
emit()
|
|
95
|
+
return error
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const read = () => {
|
|
99
|
+
if (!native || disposed || value.state === 'error') {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const next = JSON.parse(native.snapshot()) as NativeSnapshot
|
|
104
|
+
|
|
105
|
+
if (next.state === 'error') {
|
|
106
|
+
throw new Error(next.error ?? 'Audio playback failed')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
value = {
|
|
110
|
+
state: value.state === 'waiting' && next.state === 'ended' ? 'waiting' : next.state,
|
|
111
|
+
currentTime: Number.isFinite(next.currentTime) ? Math.max(0, next.currentTime) : 0,
|
|
112
|
+
duration: Number.isFinite(next.duration) ? Math.max(0, next.duration) : 0,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (pending && next.state !== 'loading') {
|
|
116
|
+
pending.resolve()
|
|
117
|
+
pending = undefined
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const tick = () => {
|
|
122
|
+
if (disposed) {
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
read()
|
|
128
|
+
} catch (cause) {
|
|
129
|
+
fail(cause)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (value.state === 'ended') {
|
|
134
|
+
if (index + 1 < queue.length) {
|
|
135
|
+
index++
|
|
136
|
+
// Native notifications never own a rejected JS promise.
|
|
137
|
+
void load(true).catch(() => {})
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!queueComplete) {
|
|
142
|
+
value = { ...value, state: 'waiting' }
|
|
143
|
+
waitingToResume = true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
stopTimer()
|
|
147
|
+
} else if (!pending && value.state !== 'playing' && value.state !== 'loading') {
|
|
148
|
+
// Paused/idle is stable — the poll only exists to observe loading
|
|
149
|
+
// resolution, playing progress, and the ended auto-advance.
|
|
150
|
+
stopTimer()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
emit()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const load = async (autoplay = false) => {
|
|
157
|
+
const ownGeneration = ++generation
|
|
158
|
+
const ownPlayRequest = playRequest
|
|
159
|
+
|
|
160
|
+
pending?.reject(new Error('Audio load was superseded'))
|
|
161
|
+
pending = undefined
|
|
162
|
+
stopTimer()
|
|
163
|
+
value = { state: queue[index] ? 'loading' : 'idle', currentTime: 0, duration: 0 }
|
|
164
|
+
try {
|
|
165
|
+
native?.clear()
|
|
166
|
+
} catch (cause) {
|
|
167
|
+
throw fail(cause)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
emit()
|
|
171
|
+
if (!queue[index] || disposed || ownGeneration !== generation) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!native) {
|
|
176
|
+
throw fail(
|
|
177
|
+
new Error('macOS audio bridge is unavailable; rebuild the app with @octane-xplat/audio'),
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let resolveReady!: () => void
|
|
182
|
+
let rejectReady!: (error: Error) => void
|
|
183
|
+
const ready = new Promise<void>((resolve, reject) => {
|
|
184
|
+
resolveReady = resolve
|
|
185
|
+
rejectReady = reject
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
pending = { promise: ready, resolve: resolveReady, reject: rejectReady }
|
|
189
|
+
// Attach before bridge calls, which may fail synchronously.
|
|
190
|
+
ready.catch(() => {})
|
|
191
|
+
try {
|
|
192
|
+
native.setPlaybackRate(playbackRate)
|
|
193
|
+
native.setVolume(volume)
|
|
194
|
+
native.setMuted(muted)
|
|
195
|
+
native.setSource(queue[index]!.source)
|
|
196
|
+
timer = setInterval(tick, 100)
|
|
197
|
+
tick()
|
|
198
|
+
} catch (cause) {
|
|
199
|
+
fail(cause)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
await ready
|
|
203
|
+
if (
|
|
204
|
+
autoplay &&
|
|
205
|
+
value.state !== 'ended' &&
|
|
206
|
+
value.state !== 'waiting' &&
|
|
207
|
+
!disposed &&
|
|
208
|
+
ownGeneration === generation &&
|
|
209
|
+
ownPlayRequest === playRequest
|
|
210
|
+
) {
|
|
211
|
+
await play()
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const command = (action: (player: NativePlayer) => void) => {
|
|
216
|
+
assertActive()
|
|
217
|
+
if (value.error) {
|
|
218
|
+
throw value.error
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!native || index < 0) {
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
action(native)
|
|
227
|
+
read()
|
|
228
|
+
} catch (cause) {
|
|
229
|
+
throw fail(cause)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
timer ??= setInterval(tick, 100)
|
|
233
|
+
emit()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const play = async () => {
|
|
237
|
+
assertActive()
|
|
238
|
+
|
|
239
|
+
const ownPlayRequest = ++playRequest
|
|
240
|
+
const ownGeneration = generation
|
|
241
|
+
|
|
242
|
+
await pending?.promise
|
|
243
|
+
assertActive()
|
|
244
|
+
if (ownGeneration !== generation) {
|
|
245
|
+
throw new Error('Audio load was superseded')
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (ownPlayRequest === playRequest) {
|
|
249
|
+
command((player) => player.play())
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
capabilities: () => ({
|
|
255
|
+
supported: !!native,
|
|
256
|
+
backgroundPlayback: !!native,
|
|
257
|
+
systemControls: false,
|
|
258
|
+
userGestureRequired: false,
|
|
259
|
+
interruptions: false,
|
|
260
|
+
reason: native
|
|
261
|
+
? undefined
|
|
262
|
+
: 'macOS audio bridge is unavailable; rebuild the app with @octane-xplat/audio',
|
|
263
|
+
}),
|
|
264
|
+
snapshot: () => {
|
|
265
|
+
try {
|
|
266
|
+
read()
|
|
267
|
+
} catch (cause) {
|
|
268
|
+
fail(cause)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return snapshot()
|
|
272
|
+
},
|
|
273
|
+
subscribe: (listener) => {
|
|
274
|
+
assertActive()
|
|
275
|
+
listeners.add(listener)
|
|
276
|
+
listener(snapshot())
|
|
277
|
+
return () => {
|
|
278
|
+
listeners.delete(listener)
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
setQueue: async (tracks, startAt = 0, options = {}) => {
|
|
282
|
+
assertActive()
|
|
283
|
+
|
|
284
|
+
const next = copyQueue(tracks)
|
|
285
|
+
|
|
286
|
+
playRequest++
|
|
287
|
+
queue = next
|
|
288
|
+
queueComplete = options.complete ?? true
|
|
289
|
+
waitingToResume = false
|
|
290
|
+
index = queue.length
|
|
291
|
+
? Math.max(
|
|
292
|
+
0,
|
|
293
|
+
Math.min(Number.isFinite(startAt) ? Math.floor(startAt) : 0, queue.length - 1),
|
|
294
|
+
)
|
|
295
|
+
: -1
|
|
296
|
+
|
|
297
|
+
await load()
|
|
298
|
+
},
|
|
299
|
+
play,
|
|
300
|
+
pause: async () => {
|
|
301
|
+
playRequest++
|
|
302
|
+
waitingToResume = false
|
|
303
|
+
command((player) => player.pause())
|
|
304
|
+
},
|
|
305
|
+
seek: async (seconds) => {
|
|
306
|
+
assertActive()
|
|
307
|
+
if (Number.isFinite(seconds)) {
|
|
308
|
+
command((player) => player.seekSeconds(Math.max(0, seconds)))
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
updateQueue: async (tracks, options = {}) => {
|
|
313
|
+
assertActive()
|
|
314
|
+
|
|
315
|
+
const next = copyQueue(tracks)
|
|
316
|
+
const current = queue[index]
|
|
317
|
+
const at = current
|
|
318
|
+
? next.findIndex((t) => t.id === current.id && t.source === current.source)
|
|
319
|
+
: -1
|
|
320
|
+
|
|
321
|
+
queue = next
|
|
322
|
+
queueComplete = options.complete ?? queueComplete
|
|
323
|
+
if (at < 0) {
|
|
324
|
+
playRequest++
|
|
325
|
+
waitingToResume = false
|
|
326
|
+
index = next.length ? 0 : -1
|
|
327
|
+
await load()
|
|
328
|
+
} else {
|
|
329
|
+
index = at
|
|
330
|
+
if (value.state === 'waiting' && waitingToResume && index + 1 < queue.length) {
|
|
331
|
+
waitingToResume = false
|
|
332
|
+
index++
|
|
333
|
+
await load(true)
|
|
334
|
+
} else if (value.state === 'waiting' && queueComplete) {
|
|
335
|
+
value = { ...value, state: 'ended' }
|
|
336
|
+
waitingToResume = false
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
emit()
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
setPlaybackRate: async (rate) => {
|
|
343
|
+
assertActive()
|
|
344
|
+
|
|
345
|
+
const next = bounded(rate, 0.5, 3)
|
|
346
|
+
|
|
347
|
+
native?.setPlaybackRate(next)
|
|
348
|
+
playbackRate = next
|
|
349
|
+
emit()
|
|
350
|
+
},
|
|
351
|
+
setVolume: async (gain) => {
|
|
352
|
+
assertActive()
|
|
353
|
+
|
|
354
|
+
const next = bounded(gain, 0, 1)
|
|
355
|
+
|
|
356
|
+
native?.setVolume(next)
|
|
357
|
+
volume = next
|
|
358
|
+
emit()
|
|
359
|
+
},
|
|
360
|
+
setMuted: async (value) => {
|
|
361
|
+
assertActive()
|
|
362
|
+
native?.setMuted(value)
|
|
363
|
+
muted = value
|
|
364
|
+
emit()
|
|
365
|
+
},
|
|
366
|
+
dispose: () => {
|
|
367
|
+
if (disposed) {
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
disposed = true
|
|
372
|
+
generation++
|
|
373
|
+
pending?.reject(new Error('AudioPlayer is disposed'))
|
|
374
|
+
pending = undefined
|
|
375
|
+
stopTimer()
|
|
376
|
+
listeners.clear()
|
|
377
|
+
queue = []
|
|
378
|
+
index = -1
|
|
379
|
+
value = { state: 'idle', currentTime: 0, duration: 0 }
|
|
380
|
+
native?.dispose()
|
|
381
|
+
},
|
|
382
|
+
}
|
|
278
383
|
}
|
package/src/audio.ts
CHANGED
|
@@ -3,14 +3,15 @@ import { createAudioPlayer as createAndroidAudioPlayer } from './audio.android'
|
|
|
3
3
|
import { createAudioPlayer as createIOSAudioPlayer } from './audio.ios'
|
|
4
4
|
import type { AudioPlayer } from './types'
|
|
5
5
|
|
|
6
|
+
/** Create an independent player on web/iOS/macOS; Android owns one app playback service. */
|
|
6
7
|
export const createAudioPlayer = (): AudioPlayer => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if (Application.android) {
|
|
9
|
+
return createAndroidAudioPlayer()
|
|
10
|
+
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (Application.ios) {
|
|
13
|
+
return createIOSAudioPlayer()
|
|
14
|
+
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
throw new Error('@octane-xplat/audio requires iOS or Android')
|
|
16
17
|
}
|