@simba-dev/react-native-media-player 3.3.5 → 3.3.7
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/CHANGELOG.md +118 -0
- package/README.md +3 -2
- package/android/src/main/java/com/simba/player/MediaPlaybackService.kt +30 -35
- package/android/src/main/java/com/simba/player/NotificationArtwork.kt +268 -0
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +33 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,122 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
## [3.3.7] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **The media notification could abort the process — the framework was handed the same bitmap twice.**
|
|
8
|
+
Playing a radio station on API 37 killed the app with an abort from the platform's own
|
|
9
|
+
file-descriptor sanitizer:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Abort message: 'fdsan: failed to exchange ownership of file descriptor:
|
|
13
|
+
fd 223 is owned by unique_fd 0x79cc1c6e311c, was expected to be unowned'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The stack is the notification build, not the player:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
MediaPlaybackService.buildNotification
|
|
20
|
+
MediaPlaybackService.handleStart
|
|
21
|
+
Notification$Builder.build
|
|
22
|
+
Notification.reduceImageSizes
|
|
23
|
+
Icon.scaleDownToAshmem
|
|
24
|
+
BitmapCache.getShared
|
|
25
|
+
Bitmap.asShared
|
|
26
|
+
Bitmap.createAshmemBitmap
|
|
27
|
+
...
|
|
28
|
+
ashmem_create_region
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The fd table in the same tombstone holds TWO descriptors on the SAME ashmem region — fd 145
|
|
32
|
+
(unowned) and fd 223 (owned by unique_fd) — which is the framework in the middle of making a
|
|
33
|
+
shared copy of an icon bitmap whose pixels already lived in a shared region.
|
|
34
|
+
|
|
35
|
+
**⇒ THE CAUSE: the notification handed the framework a bitmap it had already been handed.** The
|
|
36
|
+
framework SHARES the icon bitmap it is given — `Icon.scaleDownToAshmem` turns it into an
|
|
37
|
+
ashmem-backed bitmap so the system UI can read it. The notification was rebuilt once a second, and
|
|
38
|
+
on every start it was built TWICE back to back — once inside `applyMetadata()` and once for
|
|
39
|
+
`startForeground()` — and BOTH builds handed over the SAME instance whenever the artwork could
|
|
40
|
+
not be loaded: the radio rows pass a REMOTE image URL, that fetch failed ("Failed to load
|
|
41
|
+
artwork" appeared once per second in logcat), and both builds fell back to
|
|
42
|
+
`BitmapFactory.decodeResource(resources, android.R.drawable.ic_media_play)` — the
|
|
43
|
+
RESOURCES-CACHED bitmap, one instance shared with every other user of that drawable.
|
|
44
|
+
|
|
45
|
+
**The fix:**
|
|
46
|
+
- a new owner, `NotificationArtwork`, hands the notification a FRESH copy on every build. The
|
|
47
|
+
bitmap it owns is never handed to the framework — only copies of it are — so the framework's
|
|
48
|
+
sharing can never touch the source;
|
|
49
|
+
- the fallback is now OUR copy of the drawable, not the Resources-cached instance;
|
|
50
|
+
- the artwork is fetched OFF the notification thread, once per artwork path. It used to be
|
|
51
|
+
fetched while the notification was being built — once a second, with a 3 s connect and a 5 s
|
|
52
|
+
read timeout, on the main thread.
|
|
53
|
+
|
|
54
|
+
The notification now shows the artwork a beat after the track starts (the fetch is asynchronous),
|
|
55
|
+
and the fallback path — the one the radio rows always took — is the one that is now safe.
|
|
56
|
+
|
|
57
|
+
### Not claimed
|
|
58
|
+
|
|
59
|
+
- This release does **not** claim the crash is gone. It was **intermittent**: the same station
|
|
60
|
+
played for the whole observation window on the re-test, with the process alive and the position
|
|
61
|
+
advancing (21947 → 22946 → 23850 → 24939 ms). What this release removes is the **mechanism**
|
|
62
|
+
that was measured — the framework being handed the same bitmap instance twice, and being handed
|
|
63
|
+
the Resources-cached bitmap at all. A platform `fdsan` abort is not something this library can
|
|
64
|
+
reproduce on demand, so the claim is about the construction, not about a reproduced crash.
|
|
65
|
+
|
|
66
|
+
- This release does **not** fix the radio artwork FETCH. The radio rows pass a REMOTE image URL and
|
|
67
|
+
that fetch failed on device. The log line is now written once per artwork path instead of once
|
|
68
|
+
per second, but the image still may not arrive.
|
|
69
|
+
|
|
70
|
+
- The artwork is fetched on a background thread, so the FIRST notification after a track starts
|
|
71
|
+
shows the fallback for up to one ticker tick (1 s) before the real artwork arrives.
|
|
72
|
+
|
|
73
|
+
- iOS is untouched — this library ships Android only.
|
|
74
|
+
|
|
75
|
+
## [3.3.6] - 2026-11-06
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
|
|
79
|
+
- **A REFUSED Picture-in-Picture entry left the app with NO controls at all.** The entry path hides
|
|
80
|
+
your chrome before it asks the OS for the window. If the OS then **refused** the entry, the
|
|
81
|
+
chrome was never brought back: `restoreConsumerChrome()` was called from exactly one place —
|
|
82
|
+
`onPictureInPictureModeChanged(false)` — and a refused entry never produces a Picture-in-Picture
|
|
83
|
+
mode change, because the app never entered Picture-in-Picture.
|
|
84
|
+
|
|
85
|
+
Measured on emulator-5554 (API 37) on 2026-11-06, on the npm 3.3.5 build, with the platform
|
|
86
|
+
appop `PICTURE_IN_PICTURE` denied so the OS refuses the entry:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
18:14:49.334 hideConsumerChrome: hid the chrome view with nativeID 'simba-expanded-chrome' visibility=8
|
|
90
|
+
18:14:49.348 the OS refused the PiP entry
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`restoreConsumerChrome` **never ran**. The app came back to the player with no header, no scrub
|
|
94
|
+
row and no transport row — just the video, with nothing to control it with. Tapping the video did
|
|
95
|
+
not bring it back, and the only recovery was killing the app.
|
|
96
|
+
|
|
97
|
+
**The fix:** the refusal branch brings the chrome back itself, before it returns. It calls the
|
|
98
|
+
**one** owner — `restoreConsumerChrome()` — which forgets the hidden view as it restores it, so
|
|
99
|
+
the refusal path and the Picture-in-Picture-exit path can both call it and the chrome is restored
|
|
100
|
+
**exactly once**: whichever path gets there first restores it, and the other finds nothing to do
|
|
101
|
+
and does nothing. A guard that returns *before* the hide (the API level, the auto-enter policy,
|
|
102
|
+
already-in-Picture-in-Picture, no media loaded) restores nothing, because nothing was hidden.
|
|
103
|
+
|
|
104
|
+
The README said the chrome is brought back "when Picture-in-Picture ends". That was **false** for
|
|
105
|
+
a refused entry, and the README is the documentation every consumer installs — so it now says
|
|
106
|
+
"when Picture-in-Picture ends **or when the OS refuses the entry**".
|
|
107
|
+
|
|
108
|
+
### Not claimed
|
|
109
|
+
|
|
110
|
+
- This release does **not** claim to fix the chrome that is still in the Picture-in-Picture window
|
|
111
|
+
on a successful entry. That is **B-050**, and its cause is measured: the hide and the entry run
|
|
112
|
+
in the **same main-thread message**, so no traversal can run between them, so the chrome-less
|
|
113
|
+
frame is never drawn, and the Picture-in-Picture window keeps a **frozen snapshot** of the app's
|
|
114
|
+
last drawn UI layer while its video layer stays live. The 3.3.5 CHANGELOG's "Not claimed" section
|
|
115
|
+
says so in full, and nothing in this release changes it.
|
|
116
|
+
|
|
117
|
+
- The JavaScript-button entry path is unchanged: the consumer unmounts its own chrome in React
|
|
118
|
+
there, so the library never hides it natively and there is nothing to restore.
|
|
119
|
+
|
|
2
120
|
## [3.3.5] - 2026-11-06
|
|
3
121
|
|
|
4
122
|
### Fixed
|
package/README.md
CHANGED
|
@@ -387,8 +387,9 @@ path. The same library call serves both, so there is one entry and one owner. Wh
|
|
|
387
387
|
hook matters is in [Why it is native](#why-it-is-native-and-why-your-activity-hands-over-the-activity).
|
|
388
388
|
|
|
389
389
|
The library then hides your chrome, asks the OS for the window, and brings your chrome back when
|
|
390
|
-
Picture-in-Picture ends
|
|
391
|
-
|
|
390
|
+
Picture-in-Picture ends **— or when the OS refuses the entry**, which produces no Picture-in-Picture
|
|
391
|
+
mode change to restore it from. It returns whether the OS **accepted** the entry, and `false` when
|
|
392
|
+
the entry was refused, so you can log it:
|
|
392
393
|
|
|
393
394
|
```kotlin
|
|
394
395
|
val entered = com.simba.player.mpv.MpvBridgeModule.notifyUserLeaveHint(this)
|
|
@@ -8,8 +8,6 @@ import android.app.Service
|
|
|
8
8
|
import android.content.Context
|
|
9
9
|
import android.content.Intent
|
|
10
10
|
import android.content.pm.PackageManager
|
|
11
|
-
import android.graphics.Bitmap
|
|
12
|
-
import android.graphics.BitmapFactory
|
|
13
11
|
import android.os.Build
|
|
14
12
|
import android.os.Handler
|
|
15
13
|
import android.os.IBinder
|
|
@@ -20,8 +18,6 @@ import android.support.v4.media.session.PlaybackStateCompat
|
|
|
20
18
|
import android.util.Log
|
|
21
19
|
import androidx.core.app.NotificationCompat
|
|
22
20
|
import com.simba.player.mpv.MPVLib
|
|
23
|
-
import java.io.File
|
|
24
|
-
import java.net.URL
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* V20 Phase B: the foreground service that owns playback.
|
|
@@ -297,6 +293,14 @@ class MediaPlaybackService : Service() {
|
|
|
297
293
|
private var currentArtist: String = ""
|
|
298
294
|
private var currentAlbum: String = ""
|
|
299
295
|
private var currentArtworkPath: String = ""
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The artwork for the media notification.
|
|
299
|
+
*
|
|
300
|
+
* It owns the rules that keep the notification from taking the process
|
|
301
|
+
* down - see `NotificationArtwork` for the measurement.
|
|
302
|
+
*/
|
|
303
|
+
private lateinit var notificationArtwork: NotificationArtwork
|
|
300
304
|
private var currentPosition: Long = 0L
|
|
301
305
|
private var currentDuration: Long = 0L
|
|
302
306
|
private var isCurrentlyPlaying: Boolean = true
|
|
@@ -377,6 +381,7 @@ class MediaPlaybackService : Service() {
|
|
|
377
381
|
instance = this
|
|
378
382
|
notificationManager = getSystemService(NotificationManager::class.java)
|
|
379
383
|
createNotificationChannel()
|
|
384
|
+
notificationArtwork = NotificationArtwork(resources)
|
|
380
385
|
createMediaSession()
|
|
381
386
|
Log.i(TAG, "MediaPlaybackService created (session owned by service)")
|
|
382
387
|
}
|
|
@@ -397,6 +402,7 @@ class MediaPlaybackService : Service() {
|
|
|
397
402
|
// onDestroy. Doing it in an Activity's is what tied the session's
|
|
398
403
|
// lifetime to a window.
|
|
399
404
|
stopTicker("service destroyed")
|
|
405
|
+
if (::notificationArtwork.isInitialized) notificationArtwork.release()
|
|
400
406
|
releaseMediaSession()
|
|
401
407
|
isRunning = false
|
|
402
408
|
instance = null
|
|
@@ -585,7 +591,7 @@ class MediaPlaybackService : Service() {
|
|
|
585
591
|
if (title.isNotBlank()) currentTitle = title
|
|
586
592
|
currentArtist = artist
|
|
587
593
|
currentAlbum = album
|
|
588
|
-
|
|
594
|
+
setArtworkPath(artworkPath)
|
|
589
595
|
|
|
590
596
|
val session = mediaSession ?: return
|
|
591
597
|
val durationMs = enginePropertyMs("duration")
|
|
@@ -616,7 +622,7 @@ class MediaPlaybackService : Service() {
|
|
|
616
622
|
currentTitle = extras?.getString(EXTRA_TITLE) ?: "Simba Player"
|
|
617
623
|
currentArtist = extras?.getString(EXTRA_ARTIST) ?: ""
|
|
618
624
|
currentAlbum = extras?.getString(EXTRA_ALBUM) ?: ""
|
|
619
|
-
|
|
625
|
+
setArtworkPath(extras?.getString(EXTRA_ARTWORK_PATH) ?: "")
|
|
620
626
|
currentPosition = extras?.getLong(EXTRA_POSITION_MS, 0L) ?: 0L
|
|
621
627
|
currentDuration = extras?.getLong(EXTRA_DURATION_MS, 0L) ?: 0L
|
|
622
628
|
isCurrentlyPlaying = extras?.getBoolean(EXTRA_IS_PLAYING, true) ?: true
|
|
@@ -638,7 +644,7 @@ class MediaPlaybackService : Service() {
|
|
|
638
644
|
extras.getString(EXTRA_TITLE)?.let { currentTitle = it }
|
|
639
645
|
extras.getString(EXTRA_ARTIST)?.let { currentArtist = it }
|
|
640
646
|
extras.getString(EXTRA_ALBUM)?.let { currentAlbum = it }
|
|
641
|
-
extras.getString(EXTRA_ARTWORK_PATH)?.let {
|
|
647
|
+
extras.getString(EXTRA_ARTWORK_PATH)?.let { setArtworkPath(it) }
|
|
642
648
|
extras.getLong(EXTRA_POSITION_MS, -1L).let { if (it >= 0L) currentPosition = it }
|
|
643
649
|
extras.getLong(EXTRA_DURATION_MS, -1L).let { if (it >= 0L) currentDuration = it }
|
|
644
650
|
extras.getBoolean(EXTRA_IS_PLAYING, isCurrentlyPlaying)?.also { isCurrentlyPlaying = it }
|
|
@@ -691,14 +697,14 @@ class MediaPlaybackService : Service() {
|
|
|
691
697
|
else -> ""
|
|
692
698
|
}
|
|
693
699
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
)
|
|
700
|
+
// A FRESH bitmap for this build. The framework shares the icon
|
|
701
|
+
// bitmap it is handed, so handing it the same instance twice is
|
|
702
|
+
// what aborted the process - see `NotificationArtwork`.
|
|
703
|
+
val artworkBitmap = notificationArtwork.bitmapForNotification()
|
|
698
704
|
|
|
699
705
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
|
|
700
706
|
.setSmallIcon(android.R.drawable.ic_media_play)
|
|
701
|
-
.setLargeIcon(
|
|
707
|
+
.setLargeIcon(artworkBitmap)
|
|
702
708
|
.setContentTitle(currentTitle)
|
|
703
709
|
.setContentText(subtitle)
|
|
704
710
|
.setContentIntent(buildContentIntent(this))
|
|
@@ -750,29 +756,18 @@ class MediaPlaybackService : Service() {
|
|
|
750
756
|
return builder.build()
|
|
751
757
|
}
|
|
752
758
|
|
|
753
|
-
// ── Artwork
|
|
759
|
+
// ── Artwork ────────────────────────────────────────────────────────────
|
|
754
760
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
val file = File(path)
|
|
767
|
-
if (file.exists()) {
|
|
768
|
-
BitmapFactory.decodeFile(file.absolutePath)
|
|
769
|
-
} else {
|
|
770
|
-
null
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
} catch (e: Exception) {
|
|
774
|
-
Log.w(TAG, "Failed to load artwork: ${e.message}")
|
|
775
|
-
null
|
|
776
|
-
}
|
|
761
|
+
/**
|
|
762
|
+
* Point the notification at an artwork path.
|
|
763
|
+
*
|
|
764
|
+
* The artwork is told about the path HERE, in one place, so it can be
|
|
765
|
+
* fetched OFF the notification thread. Telling it in the notification
|
|
766
|
+
* builder instead would fetch the image while the notification is being
|
|
767
|
+
* built - once a second.
|
|
768
|
+
*/
|
|
769
|
+
private fun setArtworkPath(path: String) {
|
|
770
|
+
currentArtworkPath = path
|
|
771
|
+
notificationArtwork.request(path)
|
|
777
772
|
}
|
|
778
773
|
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
package com.simba.player
|
|
2
|
+
|
|
3
|
+
import android.content.res.Resources
|
|
4
|
+
import android.graphics.Bitmap
|
|
5
|
+
import android.graphics.BitmapFactory
|
|
6
|
+
import android.os.Handler
|
|
7
|
+
import android.os.Looper
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import java.io.File
|
|
10
|
+
import java.net.URL
|
|
11
|
+
import java.util.concurrent.Executors
|
|
12
|
+
import kotlin.math.max
|
|
13
|
+
import kotlin.math.roundToInt
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The artwork that goes into the media notification.
|
|
17
|
+
*
|
|
18
|
+
* ## Why this class exists
|
|
19
|
+
*
|
|
20
|
+
* The notification was rebuilt once a second, and every rebuild re-fetched
|
|
21
|
+
* the artwork over the network ON THE NOTIFICATION THREAD and then handed
|
|
22
|
+
* the framework a bitmap the framework had already been handed before.
|
|
23
|
+
*
|
|
24
|
+
* That second half is what killed the app. Measured on emulator-5554
|
|
25
|
+
* (API 37) on 2026-11-19, from the tombstone of the crash:
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* Abort message: 'fdsan: failed to exchange ownership of file descriptor:
|
|
29
|
+
* fd 223 is owned by unique_fd 0x79cc1c6e311c, was expected to be unowned'
|
|
30
|
+
*
|
|
31
|
+
* MediaPlaybackService.buildNotification
|
|
32
|
+
* MediaPlaybackService.handleStart
|
|
33
|
+
* Notification$Builder.build
|
|
34
|
+
* Notification.reduceImageSizes
|
|
35
|
+
* Icon.scaleDownToAshmem
|
|
36
|
+
* BitmapCache.getShared
|
|
37
|
+
* Bitmap.asShared
|
|
38
|
+
* Bitmap.createAshmemBitmap
|
|
39
|
+
* ashmem_create_region
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* The fd table in that same tombstone holds TWO descriptors on the SAME
|
|
43
|
+
* ashmem region - fd 145 (unowned) and fd 223 (owned by unique_fd) - which
|
|
44
|
+
* is the framework in the middle of making a shared copy of an icon bitmap
|
|
45
|
+
* whose pixels already lived in a shared region.
|
|
46
|
+
*
|
|
47
|
+
* The framework SHARES the icon bitmap it is handed: `Icon.scaleDownToAshmem`
|
|
48
|
+
* turns it into an ashmem-backed bitmap so the system UI can read it. Hand
|
|
49
|
+
* the framework the same instance twice and the second handover operates on
|
|
50
|
+
* a bitmap that is already shared.
|
|
51
|
+
*
|
|
52
|
+
* And the same instance WAS handed twice, back to back, on every start:
|
|
53
|
+
*
|
|
54
|
+
* - `handleStart` builds the notification twice - once inside
|
|
55
|
+
* `applyMetadata` and once for `startForeground`;
|
|
56
|
+
* - when the artwork could not be loaded (the radio rows pass a REMOTE
|
|
57
|
+
* image URL, and that fetch failed - "Failed to load artwork" appeared
|
|
58
|
+
* once per second in logcat) BOTH builds fell back to
|
|
59
|
+
* `BitmapFactory.decodeResource(resources, android.R.drawable.ic_media_play)`,
|
|
60
|
+
* which is the RESOURCES-CACHED bitmap: one instance, shared with every
|
|
61
|
+
* other user of that drawable, handed to the framework twice.
|
|
62
|
+
*
|
|
63
|
+
* ## The three rules this class enforces
|
|
64
|
+
*
|
|
65
|
+
* 1. The framework is handed a FRESH bitmap on every notification build.
|
|
66
|
+
* The bitmap this class owns is never handed over - only copies of it
|
|
67
|
+
* are.
|
|
68
|
+
* 2. The fallback is OUR copy of the drawable, not the Resources-cached
|
|
69
|
+
* instance.
|
|
70
|
+
* 3. The artwork is fetched OFF the notification thread, once per artwork
|
|
71
|
+
* path - not once per notification build.
|
|
72
|
+
*/
|
|
73
|
+
class NotificationArtwork(private val resources: Resources) {
|
|
74
|
+
|
|
75
|
+
companion object {
|
|
76
|
+
private const val TAG = "NotificationArtwork"
|
|
77
|
+
|
|
78
|
+
private const val CONNECT_TIMEOUT_MS = 3000
|
|
79
|
+
private const val READ_TIMEOUT_MS = 5000
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The path the notification is currently meant to show. */
|
|
83
|
+
private var requestedPath: String = ""
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Our own copy of the drawable fallback.
|
|
87
|
+
*
|
|
88
|
+
* `BitmapFactory.decodeResource` hands back the RESOURCES-CACHED
|
|
89
|
+
* bitmap - one instance, shared with every other user of that drawable.
|
|
90
|
+
* Handing that to the framework would let the framework share a bitmap
|
|
91
|
+
* the whole Resources cache still points at.
|
|
92
|
+
*/
|
|
93
|
+
private val fallback: Bitmap? =
|
|
94
|
+
privateCopy(BitmapFactory.decodeResource(resources, android.R.drawable.ic_media_play))
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The source bitmap.
|
|
98
|
+
*
|
|
99
|
+
* NEVER handed to the framework: only copies of it are. The framework
|
|
100
|
+
* shares the bitmap it is given, so a bitmap that has been handed over
|
|
101
|
+
* once must never be handed over again.
|
|
102
|
+
*/
|
|
103
|
+
private var source: Bitmap? = fallback
|
|
104
|
+
|
|
105
|
+
/** The loader thread posts its results back to the main looper. */
|
|
106
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The thread the artwork is fetched on.
|
|
110
|
+
*
|
|
111
|
+
* The fetch is network I/O with a 3 s connect and a 5 s read timeout.
|
|
112
|
+
* Doing it on the notification thread meant every notification build
|
|
113
|
+
* could block the main thread for seconds - and it happened once a
|
|
114
|
+
* second.
|
|
115
|
+
*/
|
|
116
|
+
private val loader = Executors.newSingleThreadExecutor { runnable ->
|
|
117
|
+
Thread(runnable, "simba-artwork").apply { isDaemon = true }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Tell the artwork what the notification should show.
|
|
122
|
+
*
|
|
123
|
+
* Safe to call as often as the service hears about a path: the fetch
|
|
124
|
+
* only starts when the path actually changed.
|
|
125
|
+
*/
|
|
126
|
+
fun request(path: String) {
|
|
127
|
+
val wanted = ArtworkPath.normalize(path)
|
|
128
|
+
if (wanted == requestedPath) return
|
|
129
|
+
requestedPath = wanted
|
|
130
|
+
|
|
131
|
+
if (wanted.isEmpty()) {
|
|
132
|
+
source = fallback
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The previous artwork must not keep showing while the new one
|
|
137
|
+
// loads - and the fallback is safer than the last track's artwork.
|
|
138
|
+
source = fallback
|
|
139
|
+
|
|
140
|
+
loader.execute {
|
|
141
|
+
val decoded = decode(wanted)
|
|
142
|
+
mainHandler.post {
|
|
143
|
+
// The path may have changed while the fetch was in flight.
|
|
144
|
+
if (wanted == requestedPath) source = decoded ?: fallback
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The bitmap for ONE notification build.
|
|
151
|
+
*
|
|
152
|
+
* Always a fresh instance - see the class docblock. A null means the
|
|
153
|
+
* caller should show no large icon at all.
|
|
154
|
+
*/
|
|
155
|
+
fun bitmapForNotification(): Bitmap? = privateCopy(source)
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Stop the loader.
|
|
159
|
+
*
|
|
160
|
+
* The bitmaps are NOT recycled: the copies the framework holds are its
|
|
161
|
+
* own, and recycling a bitmap that a pending copy might still be
|
|
162
|
+
* reading is a crash waiting to happen. They are small, and the
|
|
163
|
+
* service dies with the app.
|
|
164
|
+
*/
|
|
165
|
+
fun release() {
|
|
166
|
+
loader.shutdownNow()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Fetch and shrink the artwork.
|
|
171
|
+
*
|
|
172
|
+
* Runs on the loader thread, never on the notification thread.
|
|
173
|
+
*/
|
|
174
|
+
private fun decode(path: String): Bitmap? {
|
|
175
|
+
return try {
|
|
176
|
+
val decoded = if (ArtworkPath.isRemote(path)) {
|
|
177
|
+
val connection = URL(path).openConnection()
|
|
178
|
+
connection.connectTimeout = CONNECT_TIMEOUT_MS
|
|
179
|
+
connection.readTimeout = READ_TIMEOUT_MS
|
|
180
|
+
connection.getInputStream().use { input ->
|
|
181
|
+
BitmapFactory.decodeStream(input)
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
val file = File(path)
|
|
185
|
+
if (file.exists()) BitmapFactory.decodeFile(file.absolutePath) else null
|
|
186
|
+
}
|
|
187
|
+
decoded?.let { shrink(it) }
|
|
188
|
+
} catch (e: Exception) {
|
|
189
|
+
Log.w(TAG, "Failed to load artwork: ${e.message}")
|
|
190
|
+
null
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Shrink a decoded bitmap to [ArtworkSizing.MAX_SOURCE_EDGE].
|
|
196
|
+
*
|
|
197
|
+
* The copy the framework receives is a copy of THIS bitmap, so the
|
|
198
|
+
* smaller it is, the cheaper every notification build is.
|
|
199
|
+
*/
|
|
200
|
+
private fun shrink(bitmap: Bitmap): Bitmap {
|
|
201
|
+
val (width, height) = ArtworkSizing.shrunkSize(bitmap.width, bitmap.height)
|
|
202
|
+
if (width == bitmap.width && height == bitmap.height) return bitmap
|
|
203
|
+
val scaled = Bitmap.createScaledBitmap(bitmap, width, height, true)
|
|
204
|
+
// The bitmap was ours alone - it was decoded here and nothing else
|
|
205
|
+
// holds it - so it can be released once the smaller copy exists.
|
|
206
|
+
if (scaled !== bitmap) bitmap.recycle()
|
|
207
|
+
return scaled
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A bitmap this class owns.
|
|
212
|
+
*
|
|
213
|
+
* `Bitmap.copy` returns a bitmap with its OWN pixels, which is what
|
|
214
|
+
* makes it safe to hand to the framework: the framework's sharing
|
|
215
|
+
* (ashmem) touches the copy, never the source.
|
|
216
|
+
*/
|
|
217
|
+
private fun privateCopy(bitmap: Bitmap?): Bitmap? =
|
|
218
|
+
try {
|
|
219
|
+
bitmap?.copy(Bitmap.Config.ARGB_8888, false)
|
|
220
|
+
} catch (e: Exception) {
|
|
221
|
+
Log.w(TAG, "Could not copy a bitmap for the notification: ${e.message}")
|
|
222
|
+
null
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The artwork's path rules - pure, with no Android in them.
|
|
228
|
+
*/
|
|
229
|
+
object ArtworkPath {
|
|
230
|
+
|
|
231
|
+
/** The path as the notification should key it. */
|
|
232
|
+
fun normalize(path: String): String = path.trim()
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Whether the path is a REMOTE image the loader has to fetch.
|
|
236
|
+
*/
|
|
237
|
+
fun isRemote(path: String): Boolean {
|
|
238
|
+
val normalized = normalize(path)
|
|
239
|
+
return normalized.startsWith("http://") || normalized.startsWith("https://")
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The artwork's sizing arithmetic - pure, with no Android in them.
|
|
245
|
+
*/
|
|
246
|
+
object ArtworkSizing {
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The longest edge the private source keeps.
|
|
250
|
+
*
|
|
251
|
+
* The notification's large icon is rendered at a few hundred pixels at
|
|
252
|
+
* most, so keeping more than this costs memory and makes the
|
|
253
|
+
* per-build copy bigger for no visible gain.
|
|
254
|
+
*/
|
|
255
|
+
const val MAX_SOURCE_EDGE = 256
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The size a source of [width] x [height] is shrunk to.
|
|
259
|
+
*
|
|
260
|
+
* A source that already fits is left alone.
|
|
261
|
+
*/
|
|
262
|
+
fun shrunkSize(width: Int, height: Int, maxEdge: Int = MAX_SOURCE_EDGE): Pair<Int, Int> {
|
|
263
|
+
val longest = max(width, height)
|
|
264
|
+
if (longest <= maxEdge) return width to height
|
|
265
|
+
val scale = maxEdge.toDouble() / longest.toDouble()
|
|
266
|
+
return max(1, (width * scale).roundToInt()) to max(1, (height * scale).roundToInt())
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -647,6 +647,24 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
647
647
|
val entered = enterPictureInPicture(activity, state = state)
|
|
648
648
|
if (!entered) {
|
|
649
649
|
Log.w(TAG, "companion.notifyUserLeaveHint: the OS refused the PiP entry")
|
|
650
|
+
// The chrome was hidden above, and a REFUSED entry never
|
|
651
|
+
// produces a PiP mode change: the app never entered PiP, so
|
|
652
|
+
// `onPictureInPictureModeChanged(false)` never runs and the
|
|
653
|
+
// restore it owns never happens.
|
|
654
|
+
//
|
|
655
|
+
// The consumer came back to the player with NO header, no
|
|
656
|
+
// scrub row and no transport row at all, and the only
|
|
657
|
+
// recovery was killing the app. Measured on emulator-5554
|
|
658
|
+
// (API 37) on 2026-11-06: the OS refused the entry and
|
|
659
|
+
// `restoreConsumerChrome` NEVER ran.
|
|
660
|
+
//
|
|
661
|
+
// So the refusal brings the chrome back ITSELF - and it
|
|
662
|
+
// calls the ONE owner, `restoreConsumerChrome()`, which
|
|
663
|
+
// forgets the hidden view as it restores it. That is what
|
|
664
|
+
// makes this call and the PiP-exit call safe to have
|
|
665
|
+
// BOTH: the second one finds nothing to restore and does
|
|
666
|
+
// nothing, so the chrome is restored exactly once.
|
|
667
|
+
restoreConsumerChrome()
|
|
650
668
|
return false
|
|
651
669
|
}
|
|
652
670
|
Log.i(TAG, "companion.notifyUserLeaveHint: entered PiP")
|
|
@@ -835,7 +853,21 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
835
853
|
/**
|
|
836
854
|
* Bring the hidden chrome back, and forget it.
|
|
837
855
|
*
|
|
838
|
-
*
|
|
856
|
+
* ## The ONE owner of the restore
|
|
857
|
+
*
|
|
858
|
+
* Two paths call it, and both go through here:
|
|
859
|
+
* - PiP ends - `onPictureInPictureModeChanged(false)`;
|
|
860
|
+
* - the OS REFUSED the entry - `notifyUserLeaveHint`, which
|
|
861
|
+
* never produces a PiP mode change at all, because the app
|
|
862
|
+
* never entered PiP.
|
|
863
|
+
*
|
|
864
|
+
* It forgets the hidden view as it restores it, so a second call
|
|
865
|
+
* finds nothing to do: whichever path gets there first restores
|
|
866
|
+
* the chrome, and the other one does nothing. The chrome is
|
|
867
|
+
* restored exactly once, and never zero times.
|
|
868
|
+
*
|
|
869
|
+
* A `null` view is not a failure: nothing was hidden, so there is
|
|
870
|
+
* nothing to restore.
|
|
839
871
|
*/
|
|
840
872
|
private fun restoreConsumerChrome() {
|
|
841
873
|
val view = pipHiddenChromeView ?: return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.7",
|
|
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",
|