@simba-dev/react-native-media-player 1.14.0 → 1.16.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/android/src/main/java/com/simba/player/PlayerPackage.kt +21 -6
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +102 -28
- package/android/src/main/java/com/simba/player/mpv/MpvRenderView.kt +100 -0
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +116 -31
- package/package.json +2 -2
- package/src/bridge/MpvPlayerModule.ts +19 -2
- package/src/components/PlayerProvider.tsx +48 -37
- package/src/components/SimbaVideo.tsx +121 -0
- package/src/components/__tests__/SimbaVideo.test.tsx +164 -0
- package/src/index.ts +6 -0
- package/src/specs/SimbaVideoViewNativeComponent.ts +84 -0
- package/src/types/__tests__/player.test.tsx +123 -0
- package/src/types/player.ts +62 -14
package/src/types/player.ts
CHANGED
|
@@ -128,9 +128,20 @@ export interface PlayerProgress {
|
|
|
128
128
|
isSeeking: boolean;
|
|
129
129
|
/** True when the current file is seekable. */
|
|
130
130
|
seekable: boolean;
|
|
131
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Buffered timeline ranges, in MILLISECONDS, relative to the stream start.
|
|
133
|
+
*
|
|
134
|
+
* The same unit as `positionMs` and `durationMs`, so a consumer never
|
|
135
|
+
* has to know that mpv's own `seekable-ranges` is in seconds — the
|
|
136
|
+
* native bridge converts, because it is the only layer that knows which
|
|
137
|
+
* unit a payload carried.
|
|
138
|
+
*
|
|
139
|
+
* Empty when the source exposes no time-space cache information. A byte
|
|
140
|
+
* offset is NOT a time and is never reported here: a range painted from
|
|
141
|
+
* byte offsets would claim that unbuffered data is buffered.
|
|
142
|
+
*/
|
|
132
143
|
cacheRanges: Array<{ start: number; end: number }>;
|
|
133
|
-
/** Cache fill percent (0..100)
|
|
144
|
+
/** Cache fill percent (0..100), from mpv's `cache-buffering-state`. */
|
|
134
145
|
cacheFill: number;
|
|
135
146
|
}
|
|
136
147
|
|
|
@@ -1231,29 +1242,66 @@ export function applyPlayerEvent(
|
|
|
1231
1242
|
progress,
|
|
1232
1243
|
};
|
|
1233
1244
|
case 'onBuffering': {
|
|
1234
|
-
//
|
|
1235
|
-
//
|
|
1236
|
-
//
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1245
|
+
// The STALL signal, and the only thing that may set `isBuffering`.
|
|
1246
|
+
//
|
|
1247
|
+
// It comes from mpv's `paused-for-cache`, which is true exactly while
|
|
1248
|
+
// playback is paused because the cache underran. The payload carries
|
|
1249
|
+
// no percentage: the property does not know the fill, and the old
|
|
1250
|
+
// code invented one (0 when stalled, 100 when not) which overwrote
|
|
1251
|
+
// the real fill with a fabricated number.
|
|
1252
|
+
//
|
|
1253
|
+
// The percent-based inference is gone with the percent. A partially
|
|
1254
|
+
// filled cache is the NORMAL state during playback, so
|
|
1255
|
+
// "percent < 100" is true for most of a stream's life — reading it
|
|
1256
|
+
// as "buffering" latched the spinner on during healthy playback.
|
|
1257
|
+
const isBuffering = Boolean(p.isBuffering);
|
|
1241
1258
|
return {
|
|
1242
1259
|
state: { ...state, isBuffering },
|
|
1243
1260
|
progress: { ...progress, isBuffering },
|
|
1244
1261
|
};
|
|
1245
1262
|
}
|
|
1246
|
-
case '
|
|
1247
|
-
//
|
|
1248
|
-
//
|
|
1263
|
+
case 'onCacheFill': {
|
|
1264
|
+
// The cache FILL LEVEL — a percentage, not a stall. It comes from
|
|
1265
|
+
// mpv's `cache-buffering-state`, which changes continuously as the
|
|
1266
|
+
// cache refills, so it is a level and nothing else.
|
|
1267
|
+
//
|
|
1268
|
+
// It owns `cacheFill` and nothing else. `isBuffering` belongs to
|
|
1269
|
+
// `onBuffering`, and `cacheRanges` belongs to `onCacheState`. One
|
|
1270
|
+
// fact, one owner — the old code had two properties writing one
|
|
1271
|
+
// field with contradictory rules, and they disagreed.
|
|
1272
|
+
const percent = Number(p.percent ?? 0);
|
|
1249
1273
|
return {
|
|
1250
1274
|
state,
|
|
1251
1275
|
progress: {
|
|
1252
1276
|
...progress,
|
|
1253
|
-
|
|
1254
|
-
cacheFill: Number(p.fill ?? 0),
|
|
1277
|
+
cacheFill: Number.isFinite(percent) ? percent : 0,
|
|
1255
1278
|
},
|
|
1256
1279
|
};
|
|
1280
|
+
}
|
|
1281
|
+
case 'onCacheState': {
|
|
1282
|
+
// The buffered TIMELINE ranges, in MILLISECONDS.
|
|
1283
|
+
//
|
|
1284
|
+
// They come from mpv's `demuxer-cache-state.seekable-ranges`, which is
|
|
1285
|
+
// in seconds; the native bridge converts to milliseconds because it
|
|
1286
|
+
// is the only layer that knows which unit the payload carried. The
|
|
1287
|
+
// consumer receives one unit — the same one `positionMs` and
|
|
1288
|
+
// `durationMs` use — and never has to guess.
|
|
1289
|
+
//
|
|
1290
|
+
// A payload that carries no `ranges` at all leaves the previous value
|
|
1291
|
+
// alone. A payload that carries an EMPTY array is authoritative and
|
|
1292
|
+
// clears: that is mpv saying the cache is empty, which is different
|
|
1293
|
+
// from saying nothing.
|
|
1294
|
+
const ranges = p.ranges as
|
|
1295
|
+
| Array<{ start: number; end: number }>
|
|
1296
|
+
| undefined;
|
|
1297
|
+
return {
|
|
1298
|
+
state,
|
|
1299
|
+
progress: {
|
|
1300
|
+
...progress,
|
|
1301
|
+
cacheRanges: Array.isArray(ranges) ? ranges : progress.cacheRanges,
|
|
1302
|
+
},
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1257
1305
|
case 'onSeekable':
|
|
1258
1306
|
return {
|
|
1259
1307
|
state: { ...state, seekable: Boolean(p.seekable) },
|