@simba-dev/react-native-media-player 1.11.0 → 1.12.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.
@@ -19,8 +19,8 @@ import com.facebook.react.module.annotations.ReactModule
19
19
  import com.facebook.react.modules.core.DeviceEventManagerModule
20
20
  import com.facebook.fbreact.specs.NativeMpvPlayerSpec
21
21
  import com.simba.player.IMpvConfigProvider
22
- import com.simba.player.IMpvNativePtrProvider
23
22
  import com.simba.player.IPipModeChangeEmitter
23
+ import com.simba.player.PlaybackHost
24
24
  import org.json.JSONArray
25
25
  import org.json.JSONObject
26
26
 
@@ -34,7 +34,6 @@ import org.json.JSONObject
34
34
  class MpvBridgeModule(reactContext: ReactApplicationContext) :
35
35
  NativeMpvPlayerSpec(reactContext),
36
36
  IMpvConfigProvider,
37
- IMpvNativePtrProvider,
38
37
  IPipModeChangeEmitter {
39
38
 
40
39
  companion object {
@@ -286,8 +285,24 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
286
285
 
287
286
  // ── State ──────────────────────────────────────────────────────────────
288
287
 
289
- /** Native mpv_handle* stored as Long (0 = uninitialized). */
290
- private var nativePtr: Long = 0
288
+ /**
289
+ * V20 Phase A: the libmpv handle, *delegated* to [PlaybackHost].
290
+ *
291
+ * This is deliberately a property, not a field. It holds no state of
292
+ * its own — [PlaybackHost] is the single owner, because the handle is
293
+ * a process-global in C++ (`g_mpv`) and a React Native TurboModule
294
+ * dies with its React context, which would leave the handle owned by
295
+ * something that is not alive when playback still needs it.
296
+ *
297
+ * Keeping the name means the ~30 existing read sites are unchanged;
298
+ * what changed is that a read can no longer return a stale copy,
299
+ * because there is no longer a copy to be stale.
300
+ */
301
+ private var nativePtr: Long
302
+ get() = PlaybackHost.handle()
303
+ set(value) {
304
+ if (value == 0L) PlaybackHost.clearHandle() else PlaybackHost.publishHandle(value)
305
+ }
291
306
 
292
307
  /** Event emitter for JS-side event listeners. */
293
308
  private val eventEmitter: DeviceEventManagerModule.RCTDeviceEventEmitter by lazy {
@@ -2221,21 +2236,23 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
2221
2236
  // ── Native Pointer (for MpvRenderView) ─────────────────────────────────
2222
2237
 
2223
2238
  /**
2224
- * Phase 7: module-side accessor (Long) used by `PlayerActivity` (which
2225
- * lives in the `@simba/react-native-media-player` module and therefore
2226
- * cannot reference `MpvBridgeModule` directly) to obtain the active
2227
- * libmpv handle without crossing the Gradle module boundary.
2239
+ * The JS-facing pointer accessor.
2240
+ *
2241
+ * V20 Phase A removed its `IMpvNativePtrProvider` sibling. That
2242
+ * interface existed so `PlayerActivity` could fetch the handle across
2243
+ * a Gradle module boundary — a boundary Phase 6 had already removed
2244
+ * (see `MPVLib`'s own header). `PlayerActivity` now reads
2245
+ * `PlaybackHost` directly and registers with `whenAvailable`, so the
2246
+ * interface had no remaining consumer and was deleted rather than
2247
+ * left in place as fiction.
2228
2248
  *
2229
- * The JS-facing @ReactMethod below stays as-is to keep the public
2230
- * TurboModule API stable. The two methods share the same private
2231
- * `nativePtr` field, so they can never disagree.
2249
+ * This method stays because it is part of the published TurboModule
2250
+ * spec and removing it would be a breaking change for consumers.
2232
2251
  */
2233
- override fun fetchNativePtr(): Long = nativePtr
2234
-
2235
2252
  @ReactMethod(isBlockingSynchronousMethod = true)
2236
2253
  @Override
2237
2254
  override fun getNativePtr(): Double {
2238
- return nativePtr.toDouble()
2255
+ return PlaybackHost.handle().toDouble()
2239
2256
  }
2240
2257
 
2241
2258
  // ── Helpers ────────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "React Native video & audio player powered by libmpv — Picture-in-Picture, MediaSession, foreground service, and a customizable TypeScript UI. Built for Android. Designed as a drop-in replacement for react-native-video / react-native-track-player / expo-av. See CHANGELOG.md for per-version notes.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,30 +0,0 @@
1
- package com.simba.player
2
-
3
- /**
4
- * Module-side contract that lets non-RN consumers (e.g. `PlayerActivity`)
5
- * fetch the active libmpv native pointer without crossing the Gradle
6
- * module boundary into the consumer app's bridge code.
7
- *
8
- * Why this exists:
9
- * - `MpvBridgeModule` lives in the consumer app at
10
- * `com.simba.player.mpv.MpvBridgeModule`. The module cannot import
11
- * it directly (Gradle does not let a library depend on its consumer).
12
- * - But `PlayerActivity` (which lives in the module) needs to call
13
- * `mpvRenderView.setNativePtr(ptr)` so the SurfaceView can attach
14
- * to mpv's `wid`. That ptr is owned by `MpvBridgeModule`.
15
- * - Solution: `MpvBridgeModule` implements this interface; module
16
- * code looks it up via `reactContext.getNativeModule("MpvPlayerModule")`
17
- * and casts to `IMpvNativePtrProvider`. The cast is safe because
18
- * we control both sides of the boundary.
19
- *
20
- * Phase 7 deliverable. The bridge-side ReactMethod `getNativePtr(): Double`
21
- * remains unchanged (keeps the JS-facing API stable) — this interface is
22
- * the native-only accessor used by the module's own activity code.
23
- */
24
- interface IMpvNativePtrProvider {
25
- /**
26
- * @return the active libmpv handle as a `Long`, or `0L` if mpv has
27
- * not been initialized yet (or has been destroyed).
28
- */
29
- fun fetchNativePtr(): Long
30
- }