@octane-xplat/audio 0.19.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 -114
- package/package.json +7 -6
- package/src/audio.android.ts +190 -180
- package/src/audio.ios.ts +492 -472
- package/src/audio.macos.ts +369 -354
- package/src/audio.ts +7 -7
- package/src/audio.web.ts +303 -290
- package/src/audio.windows.ts +1 -1
- package/src/queue.ts +10 -8
- package/src/settings.ts +5 -4
- package/src/types.ts +78 -78
- package/types/generated/.tsrx-typegen-manifest.json +0 -5
- package/types/generated/audio.macos.d.ts +0 -4
- package/types/generated/audio.web.d.ts +0 -3
- package/types/generated/audio.windows.d.ts +0 -4
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,117 +1,5 @@
|
|
|
1
1
|
# `@octane-xplat/audio`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
sound-effect bank. iOS uses `AVPlayer`/`AVAudioSession` (interruption
|
|
5
|
-
handling included) and Android uses a package-owned Media3 playback service.
|
|
6
|
-
macOS uses a package-owned AVPlayer bridge. Web uses an
|
|
7
|
-
`HTMLAudioElement` plus the Media Session API for system controls.
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-audio).
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
bun add @octane-xplat/audio
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import { createAudioPlayer } from '@octane-xplat/audio'
|
|
15
|
-
|
|
16
|
-
const player = createAudioPlayer()
|
|
17
|
-
await player.setQueue([{ id: 'ep1', source: 'https://example.com/ep1.mp3' }])
|
|
18
|
-
await player.setPlaybackRate(1.5)
|
|
19
|
-
await player.setVolume(0.4)
|
|
20
|
-
await player.setMuted(false)
|
|
21
|
-
await player.play()
|
|
22
|
-
|
|
23
|
-
const off = player.subscribe((snapshot) => {
|
|
24
|
-
// { state, currentTime, duration } — poll or subscribe, your choice
|
|
25
|
-
})
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Playback features vary by target and runtime state, so call
|
|
29
|
-
`capabilities()` before promising behavior like lock-screen controls. It
|
|
30
|
-
reports `supported`, `backgroundPlayback`, `systemControls`,
|
|
31
|
-
`userGestureRequired`, and `interruptions`. The `macos` package condition
|
|
32
|
-
selects the desktop bridge without importing mobile implementations. Rebuild
|
|
33
|
-
the macOS app after installing this package. macOS reports system controls and
|
|
34
|
-
interruption recovery as unavailable; a missing bridge reports `supported: false`.
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
// Continue with the player created above.
|
|
38
|
-
const capabilities = player.capabilities()
|
|
39
|
-
console.log(capabilities.backgroundPlayback, capabilities.systemControls)
|
|
40
|
-
off()
|
|
41
|
-
player.dispose()
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
On macOS, use an absolute local path, `file:` URL, or HTTP(S) URL. Queue
|
|
45
|
-
replacement rejects obsolete pending loads and stops the previous item.
|
|
46
|
-
Malformed media, network errors, reported output errors, and loading or
|
|
47
|
-
buffering stalled for 30 seconds become terminal errors. A new queue can retry;
|
|
48
|
-
disposal stops playback and notifications. Position, duration, and seek use
|
|
49
|
-
seconds. Real audible playback remains a separate qualification gate.
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
import { createAudioPlayer } from '@octane-xplat/audio'
|
|
53
|
-
|
|
54
|
-
export async function playTrack(source: string) {
|
|
55
|
-
const player = createAudioPlayer()
|
|
56
|
-
try {
|
|
57
|
-
await player.setQueue([{ id: 'track', source }])
|
|
58
|
-
await player.play()
|
|
59
|
-
await player.seek(2.5)
|
|
60
|
-
await player.pause()
|
|
61
|
-
} finally {
|
|
62
|
-
player.dispose()
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
For short UI sounds use [`@octane-xplat/sounds`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/sounds/README.md).
|
|
68
|
-
|
|
69
|
-
Native Windows selects an unavailable leaf without loading mobile backends.
|
|
70
|
-
Creating a player throws; this import boundary does not provide Windows playback.
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
import { createAudioPlayer } from '@octane-xplat/audio'
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const candidate = createAudioPlayer()
|
|
77
|
-
candidate.dispose()
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.log('Audio unavailable:', String(error))
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Guide: [Media services](https://octane-xplat.goddardai.org/media-services); per-target
|
|
84
|
-
availability: [platform notes](https://github.com/octane-xplat/octane-xplat/blob/main/.agents/docs/notes/platform-notes.md). Exercised by
|
|
85
|
-
the harness `MediaServices` screen
|
|
86
|
-
([`packages/app/src/MediaServices.tsrx`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/app/src/MediaServices.tsrx)).
|
|
87
|
-
|
|
88
|
-
## Foreground verification
|
|
89
|
-
|
|
90
|
-
The maintained silent-WAV fixture measures observable player state against
|
|
91
|
-
fixed budgets. Run it on an owned build host and iOS simulator (or Android
|
|
92
|
-
emulator with `--target android`). Its local HTTP addresses target virtual
|
|
93
|
-
devices; physical media acceptance needs a reachable server and a separate run:
|
|
94
|
-
|
|
95
|
-
```sh
|
|
96
|
-
bun run turbo run test:browser --filter=@octane-xplat/audio -- --foreground-budgets
|
|
97
|
-
bun run turbo run test:runtime --filter=@octane-xplat/audio -- --foreground-budgets --target ios --device OWNED_UDID
|
|
98
|
-
bun run turbo run test:macos-budgets --filter=@octane-xplat/audio
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
| Measurement | Fixture ceiling |
|
|
102
|
-
| --- | --- |
|
|
103
|
-
| First observed progress after loading | 10 seconds |
|
|
104
|
-
| Preserving queue update | 250 milliseconds |
|
|
105
|
-
| Position lost during that update | 0.15 seconds |
|
|
106
|
-
| Observable seek position | 1.5 seconds |
|
|
107
|
-
| Estimated extra boundary delay | 1.5 seconds |
|
|
108
|
-
| Appended waiting queue resumes | 2 seconds |
|
|
109
|
-
| Sampled AppKit host peak RSS | 384 MiB |
|
|
110
|
-
|
|
111
|
-
These are initial fixture ceilings, not application performance guarantees.
|
|
112
|
-
Boundary timing comes from media positions and polling; it does not measure
|
|
113
|
-
an audible gap. RSS samples cover the owned AppKit process, excluding GPU and
|
|
114
|
-
other processes. Startup, leaks, durable progress, background execution and
|
|
115
|
-
physical output need separate acceptance. The
|
|
116
|
-
[packed listening/settings check](https://github.com/octane-xplat/octane-xplat/blob/main/tools/native-readiness/README.md)
|
|
117
|
-
exercises these services together in an external mobile consumer.
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-audio).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/audio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Long-form audio playback for Octane xplat",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -55,18 +55,19 @@
|
|
|
55
55
|
"test:macos-budgets": "node tests/profile-macos.mjs"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@octane-xplat/platform": "0.
|
|
58
|
+
"@octane-xplat/platform": "0.20.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@nativescript-community/octane": "0.2.5",
|
|
62
62
|
"@nativescript/core": "9.1.3",
|
|
63
63
|
"@octanejs/vite-plugin": "0.5.0",
|
|
64
64
|
"octane": "0.16.3",
|
|
65
|
-
"tsrx-typegen": "0.
|
|
66
|
-
"typescript": "
|
|
67
|
-
"vite": "8.3.
|
|
65
|
+
"tsrx-typegen": "0.6.1",
|
|
66
|
+
"typescript": "7.1.0-beta",
|
|
67
|
+
"vite": "8.3.6",
|
|
68
68
|
"playwright": "1.63.0",
|
|
69
|
-
"@tsrx/
|
|
69
|
+
"@tsrx/content-mapper": "0.1.2",
|
|
70
|
+
"typescript-classic": "npm:typescript@5.9.3"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"@nativescript-community/octane": ">=0.2.1 <1",
|
package/src/audio.android.ts
CHANGED
|
@@ -6,188 +6,198 @@ import { android } from '@octane-xplat/platform/android'
|
|
|
6
6
|
|
|
7
7
|
// The plugin's Java bridge is exposed by NativeScript's runtime metadata.
|
|
8
8
|
declare const com: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
9
|
+
xplat: {
|
|
10
|
+
audio: {
|
|
11
|
+
AudioBridge: {
|
|
12
|
+
ACTION_QUEUE: string
|
|
13
|
+
ACTION_UPDATE: string
|
|
14
|
+
ACTION_PLAY: string
|
|
15
|
+
ACTION_PAUSE: string
|
|
16
|
+
ACTION_SEEK: string
|
|
17
|
+
ACTION_RELEASE: string
|
|
18
|
+
ACTION_RATE: string
|
|
19
|
+
ACTION_VOLUME: string
|
|
20
|
+
ACTION_MUTED: string
|
|
21
|
+
dispatch(
|
|
22
|
+
context: android.content.Context,
|
|
23
|
+
action: string,
|
|
24
|
+
payload: string,
|
|
25
|
+
index: number,
|
|
26
|
+
seconds: number,
|
|
27
|
+
): void
|
|
28
|
+
snapshot(): string
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** Create an independent player on web/iOS/macOS; Android owns one app playback service. */
|
|
35
35
|
export const createAudioPlayer = (): AudioPlayer => {
|
|
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
|
-
|
|
36
|
+
const actions = com.xplat.audio.AudioBridge
|
|
37
|
+
// `Utils.android` is a {} stub in the pinned Windows core build.
|
|
38
|
+
const context = (Utils.android as any).getApplicationContext()
|
|
39
|
+
const listeners = new Set<(snapshot: AudioSnapshot) => void>()
|
|
40
|
+
let queue: Track[] = []
|
|
41
|
+
let index = -1
|
|
42
|
+
let disposed = false
|
|
43
|
+
let playbackRate = 1
|
|
44
|
+
let volume = 1
|
|
45
|
+
let muted = false
|
|
46
|
+
let queueComplete = true
|
|
47
|
+
let poll: ReturnType<typeof setInterval> | undefined
|
|
48
|
+
|
|
49
|
+
/** The Android bridge's snapshot payload. */
|
|
50
|
+
interface SnapshotReply {
|
|
51
|
+
state: AudioSnapshot['state']
|
|
52
|
+
index?: number
|
|
53
|
+
id?: string
|
|
54
|
+
currentTime?: number
|
|
55
|
+
duration?: number
|
|
56
|
+
error?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const snapshot = (): AudioSnapshot => {
|
|
60
|
+
const parsed: unknown = JSON.parse(actions.snapshot())
|
|
61
|
+
// Bridge-supplied envelope; validated fields below, bounded once here.
|
|
62
|
+
const value = (typeof parsed === 'object' && parsed !== null ? parsed : {}) as SnapshotReply
|
|
63
|
+
|
|
64
|
+
if (Number.isInteger(value.index) && value.index! >= 0) {
|
|
65
|
+
index = value.index!
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
state: value.state,
|
|
70
|
+
playbackRate,
|
|
71
|
+
volume,
|
|
72
|
+
muted,
|
|
73
|
+
queueComplete,
|
|
74
|
+
track: value.id ? queue.find((track) => track.id === value.id) : queue[index],
|
|
75
|
+
currentTime: value.currentTime ?? 0,
|
|
76
|
+
duration: value.duration ?? 0,
|
|
77
|
+
error: value.error ? new Error(value.error) : undefined,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const emit = () => {
|
|
82
|
+
const value = snapshot()
|
|
83
|
+
|
|
84
|
+
for (const listener of listeners) {
|
|
85
|
+
listener(value)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const dispatch = (action: string, payload = '', at = 0, seconds = 0) => {
|
|
90
|
+
if (disposed) {
|
|
91
|
+
throw new Error('AudioPlayer is disposed')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
actions.dispatch(context, action, payload, at, seconds)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const ensurePolling = () => {
|
|
98
|
+
if (listeners.size && !poll) {
|
|
99
|
+
poll = setInterval(emit, 250)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!listeners.size && poll) {
|
|
103
|
+
clearInterval(poll)
|
|
104
|
+
poll = undefined
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
capabilities: (): AudioCapabilities => ({
|
|
110
|
+
supported: true,
|
|
111
|
+
backgroundPlayback: true,
|
|
112
|
+
systemControls: true,
|
|
113
|
+
userGestureRequired: false,
|
|
114
|
+
interruptions: true,
|
|
115
|
+
}),
|
|
116
|
+
snapshot,
|
|
117
|
+
subscribe: (listener) => {
|
|
118
|
+
listeners.add(listener)
|
|
119
|
+
listener(snapshot())
|
|
120
|
+
ensurePolling()
|
|
121
|
+
return () => {
|
|
122
|
+
listeners.delete(listener)
|
|
123
|
+
ensurePolling()
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
setQueue: async (tracks, startAt = 0, options = {}) => {
|
|
127
|
+
if (disposed) {
|
|
128
|
+
throw new Error('AudioPlayer is disposed')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
queue = copyQueue(tracks)
|
|
132
|
+
queueComplete = options.complete ?? true
|
|
133
|
+
index = queue.length
|
|
134
|
+
? Math.max(
|
|
135
|
+
0,
|
|
136
|
+
Math.min(Number.isFinite(startAt) ? Math.floor(startAt) : 0, queue.length - 1),
|
|
137
|
+
)
|
|
138
|
+
: -1
|
|
139
|
+
|
|
140
|
+
dispatch(
|
|
141
|
+
actions.ACTION_QUEUE,
|
|
142
|
+
JSON.stringify({ tracks: queue, complete: queueComplete }),
|
|
143
|
+
index,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
emit()
|
|
147
|
+
},
|
|
148
|
+
play: async () => dispatch(actions.ACTION_PLAY),
|
|
149
|
+
pause: async () => dispatch(actions.ACTION_PAUSE),
|
|
150
|
+
seek: async (seconds) => {
|
|
151
|
+
if (Number.isFinite(seconds)) {
|
|
152
|
+
dispatch(actions.ACTION_SEEK, '', 0, Math.max(0, seconds))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
emit()
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
updateQueue: async (tracks, options = {}) => {
|
|
159
|
+
const next = copyQueue(tracks)
|
|
160
|
+
const complete = options.complete ?? queueComplete
|
|
161
|
+
|
|
162
|
+
dispatch(actions.ACTION_UPDATE, JSON.stringify({ tracks: next, complete }))
|
|
163
|
+
queue = next
|
|
164
|
+
queueComplete = complete
|
|
165
|
+
emit()
|
|
166
|
+
},
|
|
167
|
+
setPlaybackRate: async (rate) => {
|
|
168
|
+
const next = bounded(rate, 0.5, 3)
|
|
169
|
+
|
|
170
|
+
dispatch(actions.ACTION_RATE, '', 0, next)
|
|
171
|
+
playbackRate = next
|
|
172
|
+
emit()
|
|
173
|
+
},
|
|
174
|
+
setVolume: async (gain) => {
|
|
175
|
+
const next = bounded(gain, 0, 1)
|
|
176
|
+
|
|
177
|
+
dispatch(actions.ACTION_VOLUME, '', 0, next)
|
|
178
|
+
volume = next
|
|
179
|
+
emit()
|
|
180
|
+
},
|
|
181
|
+
setMuted: async (value) => {
|
|
182
|
+
dispatch(actions.ACTION_MUTED, '', 0, value ? 1 : 0)
|
|
183
|
+
muted = value
|
|
184
|
+
emit()
|
|
185
|
+
},
|
|
186
|
+
dispose: () => {
|
|
187
|
+
if (disposed) {
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
disposed = true
|
|
192
|
+
actions.dispatch(context, actions.ACTION_RELEASE, '', 0, 0)
|
|
193
|
+
if (poll) {
|
|
194
|
+
clearInterval(poll)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
poll = undefined
|
|
198
|
+
listeners.clear()
|
|
199
|
+
queue = []
|
|
200
|
+
index = -1
|
|
201
|
+
},
|
|
202
|
+
}
|
|
193
203
|
}
|