@javascriptcommon/react-native-track-player 4.1.14 → 4.1.15

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.
@@ -21,8 +21,8 @@ object BundleUtils {
21
21
  if (!data!!.containsKey(key)) return null
22
22
  val obj = data[key]
23
23
  if (obj is String) {
24
- // Remote or Local Uri
25
- if (obj.trim { it <= ' ' }.isEmpty()) throw RuntimeException("$key: The URL cannot be empty")
24
+ // Remote or Local Uri - allow empty URLs for placeholder tracks
25
+ if (obj.trim { it <= ' ' }.isEmpty()) return Uri.EMPTY
26
26
  return Uri.parse(obj as String?)
27
27
  } else if (obj is Bundle) {
28
28
  // require/import
@@ -77,15 +77,23 @@ enum class MediaType(val value: String) {
77
77
 
78
78
 
79
79
  fun audioItem2MediaItem(audioItem: AudioItem, context: Context? = null): MediaItem {
80
+ // Check if this is a placeholder track (notPlayable flag from TrackAudioItem)
81
+ val isNotPlayable = (audioItem as? com.doublesymmetry.trackplayer.model.TrackAudioItem)?.notPlayable ?: false
82
+ val hasValidUrl = audioItem.audioUrl.isNotBlank()
83
+
80
84
  return MediaItem.Builder()
81
85
  .setMediaId(audioItem.mediaId ?: UUID.randomUUID().toString())
86
+ // Always set URI (even empty string) so ExoPlayer adds item to timeline
82
87
  .setUri(audioItem.audioUrl)
83
88
  .setMediaMetadata(
84
89
  MediaMetadata.Builder()
85
90
  .setTitle(audioItem.title)
86
91
  .setArtist(audioItem.artist)
92
+ // Mark placeholder tracks as not playable so Android Auto shows them correctly in queue
93
+ .setIsPlayable(true)
94
+ .setIsBrowsable(false)
87
95
  .setArtworkUri((
88
- if (context != null && audioItem.audioUrl.startsWith("file://")) {
96
+ if (context != null && hasValidUrl && audioItem.audioUrl.startsWith("file://")) {
89
97
  saveMediaCoverToPng(
90
98
  audioItem.audioUrl,
91
99
  context.contentResolver,
@@ -94,7 +102,7 @@ fun audioItem2MediaItem(audioItem: AudioItem, context: Context? = null): MediaIt
94
102
  ?: audioItem.artwork
95
103
  }
96
104
  else audioItem.artwork)?.toUri())
97
- .setArtworkData(if (audioItem.audioUrl.startsWith("file://")) getEmbeddedBitmapArray(
105
+ .setArtworkData(if (hasValidUrl && audioItem.audioUrl.startsWith("file://")) getEmbeddedBitmapArray(
98
106
  audioItem.audioUrl.substring(7)) else null, MediaMetadata.PICTURE_TYPE_MEDIA)
99
107
  .setExtras(Bundle().apply {
100
108
  audioItem.options?.headers?.let {
@@ -108,6 +116,7 @@ fun audioItem2MediaItem(audioItem: AudioItem, context: Context? = null): MediaIt
108
116
  }
109
117
  putString("type", audioItem.type.toString())
110
118
  putString("uri", audioItem.audioUrl)
119
+ putBoolean("notPlayable", isNotPlayable)
111
120
  }).build())
112
121
  .setTag(audioItem)
113
122
  .build()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@javascriptcommon/react-native-track-player",
3
- "version": "4.1.14",
3
+ "version": "4.1.15",
4
4
  "description": "A fully fledged audio module created for music apps",
5
5
  "main": "lib/src/index.js",
6
6
  "types": "lib/src/index.d.ts",