@molecule/app-audio-expo 0.0.1-stage → 1.0.1
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 +4 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +49 -21
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-27T18:40:47.342Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-audio-expo
|
|
@@ -30,7 +30,7 @@ setProvider(provider)
|
|
|
30
30
|
## Installation
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
npm install @molecule/app-audio-expo @molecule/app-audio @molecule/app-logger expo-audio
|
|
33
|
+
npm install @molecule/app-audio-expo @molecule/app-audio @molecule/app-logger expo-audio react-native
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## API
|
|
@@ -71,12 +71,14 @@ Peer dependencies:
|
|
|
71
71
|
- `@molecule/app-audio` ^1.0.0
|
|
72
72
|
- `@molecule/app-logger` ^1.0.0
|
|
73
73
|
- `expo-audio` 0.4.9
|
|
74
|
+
- `react-native` 0.79.6
|
|
74
75
|
|
|
75
76
|
### Runtime Dependencies
|
|
76
77
|
|
|
77
78
|
- `@molecule/app-audio`
|
|
78
79
|
- `@molecule/app-logger`
|
|
79
80
|
- `expo-audio`
|
|
81
|
+
- `react-native`
|
|
80
82
|
|
|
81
83
|
The `expo-audio` peer is pinned to the version bundled with Expo SDK 53.
|
|
82
84
|
A bare React Native app needs Expo modules installed before it can use this provider.
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2C,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAiLjG,2DAA2D;AAC3D,eAAO,MAAM,QAAQ,EAAE,aAA8C,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAudioPlayer } from 'expo-audio';
|
|
2
|
+
import { AppState, Platform } from 'react-native';
|
|
2
3
|
import { getLogger } from '@molecule/app-logger';
|
|
3
4
|
const UPDATE_INTERVAL_MS = 100;
|
|
4
5
|
const SOURCE_LOAD_TIMEOUT_MS = 10_000;
|
|
@@ -17,10 +18,12 @@ function createPlayer(options) {
|
|
|
17
18
|
let sourceIndex = 0;
|
|
18
19
|
let loadTimeout;
|
|
19
20
|
let wantsPlayback = options.autoplay ?? false;
|
|
21
|
+
let backgrounded = Platform.OS === 'android' && AppState.currentState === 'background';
|
|
20
22
|
let ended = false;
|
|
21
23
|
let destroyed = false;
|
|
22
24
|
let playRequest = 0;
|
|
23
25
|
let pendingSeek;
|
|
26
|
+
let appStateSubscription;
|
|
24
27
|
/** Seeks in seconds and lets play wait for an in-flight seek or a rewind after completion. */
|
|
25
28
|
function seekTo(time) {
|
|
26
29
|
const position = seconds(time);
|
|
@@ -52,7 +55,7 @@ function createPlayer(options) {
|
|
|
52
55
|
playRequest += 1;
|
|
53
56
|
watchSourceLoad();
|
|
54
57
|
player.replace(source);
|
|
55
|
-
if (wantsPlayback)
|
|
58
|
+
if (wantsPlayback && !backgrounded)
|
|
56
59
|
player.play();
|
|
57
60
|
}
|
|
58
61
|
/** Leaves a single source, or the last fallback, under the native player's loading policy. */
|
|
@@ -83,29 +86,52 @@ function createPlayer(options) {
|
|
|
83
86
|
if (finished && !destroyed)
|
|
84
87
|
options.onEnd?.();
|
|
85
88
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
const play = () => {
|
|
90
|
+
if (destroyed || !sources.length)
|
|
91
|
+
return;
|
|
92
|
+
wantsPlayback = true;
|
|
93
|
+
if (backgrounded)
|
|
94
|
+
return;
|
|
95
|
+
const request = ++playRequest;
|
|
96
|
+
const seek = pendingSeek ?? (ended ? seekTo(0) : undefined);
|
|
97
|
+
if (!seek) {
|
|
98
|
+
player.play();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
void seek
|
|
102
|
+
.then((ready) => {
|
|
103
|
+
if (ready && request === playRequest)
|
|
97
104
|
player.play();
|
|
105
|
+
})
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
getLogger().warn('Could not resume Expo audio playback after seeking.', { error });
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
if (Platform.OS === 'android') {
|
|
111
|
+
// The recorder temporarily disables Expo's shared background policy to
|
|
112
|
+
// keep an explicit pause. Preserve foreground-only playback on Android.
|
|
113
|
+
appStateSubscription = AppState.addEventListener('change', (state) => {
|
|
114
|
+
if (destroyed || (state !== 'active' && state !== 'background'))
|
|
98
115
|
return;
|
|
116
|
+
const nextBackgrounded = state === 'background';
|
|
117
|
+
if (backgrounded === nextBackgrounded)
|
|
118
|
+
return;
|
|
119
|
+
backgrounded = nextBackgrounded;
|
|
120
|
+
if (backgrounded) {
|
|
121
|
+
playRequest += 1;
|
|
122
|
+
if (wantsPlayback)
|
|
123
|
+
player.pause();
|
|
99
124
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
else if (wantsPlayback) {
|
|
126
|
+
play();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
watchSourceLoad();
|
|
131
|
+
if (wantsPlayback)
|
|
132
|
+
play();
|
|
133
|
+
return {
|
|
134
|
+
play,
|
|
109
135
|
pause() {
|
|
110
136
|
if (destroyed)
|
|
111
137
|
return;
|
|
@@ -140,6 +166,7 @@ function createPlayer(options) {
|
|
|
140
166
|
playRequest += 1;
|
|
141
167
|
clearTimeout(loadTimeout);
|
|
142
168
|
try {
|
|
169
|
+
appStateSubscription?.remove();
|
|
143
170
|
subscription.remove();
|
|
144
171
|
}
|
|
145
172
|
finally {
|
|
@@ -152,6 +179,7 @@ function createPlayer(options) {
|
|
|
152
179
|
catch (error) {
|
|
153
180
|
destroyed = true;
|
|
154
181
|
clearTimeout(loadTimeout);
|
|
182
|
+
appStateSubscription?.remove();
|
|
155
183
|
player.release();
|
|
156
184
|
throw error;
|
|
157
185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-audio-expo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Expo audio playback provider for molecule.dev.",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-audio-expo",
|
|
6
6
|
"type": "module",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@molecule/app-audio": "^1.0.0",
|
|
43
43
|
"@molecule/app-logger": "^1.0.0",
|
|
44
|
-
"expo-audio": "0.4.9"
|
|
44
|
+
"expo-audio": "0.4.9",
|
|
45
|
+
"react-native": "0.79.6"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@molecule/app-audio": "1.0.3",
|