@simba-dev/react-native-media-player 1.13.1 → 1.13.2
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.
|
@@ -1282,27 +1282,85 @@ class PlayerActivity : ReactActivity() {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
|
|
1284
1284
|
/**
|
|
1285
|
-
*
|
|
1286
|
-
* back while in PiP finishes the activity (exits PiP, returns to
|
|
1287
|
-
* the parent app) — back from fullscreen does default behaviour.
|
|
1288
|
-
* V12 keeps the same contract.
|
|
1285
|
+
* Back-button behaviour.
|
|
1289
1286
|
*
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1287
|
+
* ## Why this does the teardown itself
|
|
1288
|
+
*
|
|
1289
|
+
* This used to be:
|
|
1290
|
+
*
|
|
1291
|
+
* ```kotlin
|
|
1292
|
+
* if (isInPictureInPictureMode) { finish(); return }
|
|
1293
|
+
* super.onBackPressed()
|
|
1294
|
+
* ```
|
|
1295
|
+
*
|
|
1296
|
+
* which finishes the Activity **natively**. The event never reaches
|
|
1297
|
+
* React Native, so a JS `BackHandler` cannot run — which left two back
|
|
1298
|
+
* paths that disagreed:
|
|
1299
|
+
*
|
|
1300
|
+
* - the header chevron -> JS `exitPlayer()` -> stop the engine,
|
|
1301
|
+
* release the foreground service, then finish;
|
|
1302
|
+
* - the hardware key -> `super.onBackPressed()` -> finish only.
|
|
1303
|
+
*
|
|
1304
|
+
* Since the mpv engine is a process-global C++ handle that outlives any
|
|
1305
|
+
* Activity, the second path closed the window while the media carried
|
|
1306
|
+
* on: audio still audible, notification still posted, no window left to
|
|
1307
|
+
* stop it. Verified on device — after the hardware key the media
|
|
1308
|
+
* session was still `PLAYING` with zero `stopPlayback` / `nativeStop`
|
|
1309
|
+
* lines in logcat, even with a JS BackHandler registered.
|
|
1310
|
+
*
|
|
1311
|
+
* ## Why natively rather than delegating to JS
|
|
1312
|
+
*
|
|
1313
|
+
* Delegating would make the player un-closable whenever the bundle is
|
|
1314
|
+
* unhealthy — a JS crash would strand a playing session with no window
|
|
1315
|
+
* and no working dismiss. The Activity already owns the engine through
|
|
1316
|
+
* `PlaybackHost`, so the teardown here is both shorter and strictly
|
|
1317
|
+
* more robust.
|
|
1318
|
+
*
|
|
1319
|
+
* The JS `BackHandler` in `VideoPlayer.tsx` is KEPT: it covers whatever
|
|
1320
|
+
* does reach React (notably predictive back, where `onBackPressed` is
|
|
1321
|
+
* never called), and the two paths now agree.
|
|
1295
1322
|
*/
|
|
1296
1323
|
override fun onBackPressed() {
|
|
1297
1324
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode) {
|
|
1298
1325
|
// Finish exits PiP and returns the user to MainActivity (the
|
|
1299
|
-
// parent of PlayerActivity in the task stack).
|
|
1300
|
-
// V11 behaviour bit-for-bit.
|
|
1326
|
+
// parent of PlayerActivity in the task stack).
|
|
1301
1327
|
Log.i(TAG, "onBackPressed: in PiP, finishing PlayerActivity")
|
|
1302
1328
|
finish()
|
|
1303
1329
|
return
|
|
1304
1330
|
}
|
|
1305
|
-
|
|
1331
|
+
|
|
1332
|
+
// Not PiP: leaving means CLOSING. Stop the engine unconditionally —
|
|
1333
|
+
// if the service is already gone its own stop callback is not around
|
|
1334
|
+
// to do it, and leaving media running with no way to stop it is the
|
|
1335
|
+
// worse of the two failures.
|
|
1336
|
+
val ptr = PlaybackHost.handle()
|
|
1337
|
+
if (ptr != 0L) {
|
|
1338
|
+
try {
|
|
1339
|
+
MPVLib.nativeStop(ptr)
|
|
1340
|
+
Log.i(TAG, "onBackPressed: stopped mpv (ptr=$ptr)")
|
|
1341
|
+
} catch (e: Throwable) {
|
|
1342
|
+
Log.w(TAG, "onBackPressed: nativeStop threw ${e.message}")
|
|
1343
|
+
}
|
|
1344
|
+
} else {
|
|
1345
|
+
Log.w(TAG, "onBackPressed: no engine handle; nothing to stop")
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
if (MediaPlaybackService.isRunning()) {
|
|
1349
|
+
try {
|
|
1350
|
+
// Plain startService: the service is already foreground, so there
|
|
1351
|
+
// is no startForeground deadline to meet.
|
|
1352
|
+
startService(
|
|
1353
|
+
android.content.Intent(this, MediaPlaybackService::class.java).apply {
|
|
1354
|
+
action = MediaPlaybackService.ACTION_STOP
|
|
1355
|
+
},
|
|
1356
|
+
)
|
|
1357
|
+
Log.i(TAG, "onBackPressed: delivered ACTION_STOP to MediaPlaybackService")
|
|
1358
|
+
} catch (e: Throwable) {
|
|
1359
|
+
Log.e(TAG, "onBackPressed: could not deliver ACTION_STOP", e)
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
finish()
|
|
1306
1364
|
}
|
|
1307
1365
|
|
|
1308
1366
|
// ── PiP helpers (Phase 9) ──────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
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",
|