react-native-media-notification 0.3.5 → 0.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.
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
package com.mediacontrols
|
|
2
2
|
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.BitmapFactory
|
|
5
|
+
import android.graphics.drawable.BitmapDrawable
|
|
3
6
|
import android.os.Handler
|
|
4
7
|
import android.os.Looper
|
|
8
|
+
import android.webkit.URLUtil
|
|
9
|
+
import androidx.core.net.toUri
|
|
5
10
|
import androidx.media3.common.MediaItem
|
|
6
11
|
import androidx.media3.common.MediaMetadata
|
|
7
12
|
import androidx.media3.common.Player
|
|
8
13
|
import androidx.media3.common.SimpleBasePlayer
|
|
9
14
|
import androidx.media3.common.util.UnstableApi
|
|
15
|
+
import androidx.media3.session.CommandButton
|
|
10
16
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
17
|
+
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
|
|
11
18
|
import com.google.common.util.concurrent.Futures
|
|
12
19
|
import com.google.common.util.concurrent.ListenableFuture
|
|
13
20
|
import kotlinx.coroutines.CoroutineScope
|
|
14
21
|
import kotlinx.coroutines.Dispatchers
|
|
15
22
|
import kotlinx.coroutines.SupervisorJob
|
|
16
23
|
import kotlinx.coroutines.cancel
|
|
17
|
-
import
|
|
18
|
-
|
|
24
|
+
import java.io.ByteArrayOutputStream
|
|
25
|
+
|
|
19
26
|
|
|
20
27
|
@UnstableApi
|
|
21
28
|
class MediaControlsPlayer(
|
|
22
|
-
reactContext: ReactApplicationContext,
|
|
29
|
+
private val reactContext: ReactApplicationContext,
|
|
23
30
|
private val module: MediaControlsModule,
|
|
24
31
|
) : SimpleBasePlayer(Looper.getMainLooper()) {
|
|
25
32
|
|
|
@@ -155,7 +162,7 @@ class MediaControlsPlayer(
|
|
|
155
162
|
.setMediaType(MediaMetadata.MEDIA_TYPE_MUSIC)
|
|
156
163
|
.also {
|
|
157
164
|
this.currentMetadata!!.artwork?.let { artworkUrl ->
|
|
158
|
-
it.
|
|
165
|
+
it.setArtwork(artworkUrl)
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
168
|
.build()
|
|
@@ -211,6 +218,28 @@ class MediaControlsPlayer(
|
|
|
211
218
|
return this.setShuffleModeEnabled(enabled)
|
|
212
219
|
}
|
|
213
220
|
|
|
221
|
+
private fun MediaMetadata.Builder.setArtwork(artwork: String?): MediaMetadata.Builder {
|
|
222
|
+
if (artwork == null) {
|
|
223
|
+
return this
|
|
224
|
+
}
|
|
225
|
+
if (URLUtil.isValidUrl(artwork)) {
|
|
226
|
+
this.setArtworkUri(artwork.toUri())
|
|
227
|
+
} else {
|
|
228
|
+
val helper = ResourceDrawableIdHelper.getInstance()
|
|
229
|
+
val image = helper.getResourceDrawable(reactContext, artwork)
|
|
230
|
+
|
|
231
|
+
val bitmap = if (image is BitmapDrawable) {
|
|
232
|
+
image.bitmap
|
|
233
|
+
} else {
|
|
234
|
+
BitmapFactory.decodeFile(artwork)
|
|
235
|
+
}
|
|
236
|
+
val stream = ByteArrayOutputStream()
|
|
237
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream)
|
|
238
|
+
this.setArtworkData(stream.toByteArray(), MediaMetadata.PICTURE_TYPE_OTHER)
|
|
239
|
+
}
|
|
240
|
+
return this
|
|
241
|
+
}
|
|
242
|
+
|
|
214
243
|
fun setControlEnabled(controlName: Controls, enabled: Boolean) {
|
|
215
244
|
enabledControls[controlName] = enabled
|
|
216
245
|
|
|
@@ -45,7 +45,8 @@ class MediaControlsService : MediaSessionService() {
|
|
|
45
45
|
override fun onBind(intent: Intent?): IBinder {
|
|
46
46
|
return if (intent?.action == "androidx.media3.session.MediaSessionService" ||
|
|
47
47
|
intent?.action == "android.media.browse.MediaBrowserService") {
|
|
48
|
-
super.onBind(intent)
|
|
48
|
+
val binder = super.onBind(intent)
|
|
49
|
+
binder ?: this.binder
|
|
49
50
|
} else {
|
|
50
51
|
binder
|
|
51
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-media-notification",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Display and manage media style notifications based on react-native-music-control",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|