react-native-nitro-player 0.3.0-alpha.15 → 0.3.0-alpha.17

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.
Files changed (34) hide show
  1. package/README.md +29 -0
  2. package/android/src/main/java/com/margelo/nitro/nitroplayer/download/DownloadDatabase.kt +1 -0
  3. package/android/src/main/java/com/margelo/nitro/nitroplayer/playlist/PlaylistManager.kt +27 -0
  4. package/ios/core/TrackPlayerCore.swift +2 -1
  5. package/ios/download/DownloadDatabase.swift +2 -1
  6. package/ios/download/DownloadManagerCore.swift +2 -1
  7. package/ios/playlist/PlaylistManager.swift +24 -1
  8. package/lib/types/PlayerQueue.d.ts +2 -0
  9. package/nitrogen/generated/android/c++/JDownloadedPlaylist.hpp +2 -0
  10. package/nitrogen/generated/android/c++/JDownloadedTrack.hpp +2 -0
  11. package/nitrogen/generated/android/c++/JFunc_void_DownloadedTrack.hpp +2 -0
  12. package/nitrogen/generated/android/c++/JFunc_void_TrackItem_std__optional_Reason_.hpp +2 -0
  13. package/nitrogen/generated/android/c++/JFunc_void_std__string_Playlist_std__optional_QueueOperation_.hpp +2 -0
  14. package/nitrogen/generated/android/c++/JFunc_void_std__vector_Playlist__std__optional_QueueOperation_.hpp +2 -0
  15. package/nitrogen/generated/android/c++/JHybridDownloadManagerSpec.cpp +2 -0
  16. package/nitrogen/generated/android/c++/JHybridPlayerQueueSpec.cpp +2 -0
  17. package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.cpp +2 -0
  18. package/nitrogen/generated/android/c++/JPlayerState.hpp +2 -0
  19. package/nitrogen/generated/android/c++/JPlaylist.hpp +2 -0
  20. package/nitrogen/generated/android/c++/JTrackItem.hpp +9 -3
  21. package/nitrogen/generated/android/c++/JVariant_NullType_DownloadedPlaylist.hpp +2 -0
  22. package/nitrogen/generated/android/c++/JVariant_NullType_DownloadedTrack.hpp +2 -0
  23. package/nitrogen/generated/android/c++/JVariant_NullType_Playlist.hpp +2 -0
  24. package/nitrogen/generated/android/c++/JVariant_NullType_TrackItem.hpp +2 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/TrackItem.kt +7 -3
  26. package/nitrogen/generated/ios/NitroPlayer-Swift-Cxx-Bridge.hpp +16 -0
  27. package/nitrogen/generated/ios/NitroPlayer-Swift-Cxx-Umbrella.hpp +1 -0
  28. package/nitrogen/generated/ios/c++/HybridDownloadManagerSpecSwift.hpp +1 -0
  29. package/nitrogen/generated/ios/c++/HybridPlayerQueueSpecSwift.hpp +1 -0
  30. package/nitrogen/generated/ios/c++/HybridTrackPlayerSpecSwift.hpp +1 -0
  31. package/nitrogen/generated/ios/swift/TrackItem.swift +31 -1
  32. package/nitrogen/generated/shared/c++/TrackItem.hpp +7 -2
  33. package/package.json +1 -1
  34. package/src/types/PlayerQueue.ts +3 -0
package/README.md CHANGED
@@ -134,6 +134,12 @@ const tracks: TrackItem[] = [
134
134
  duration: 180.0, // in seconds
135
135
  url: 'https://example.com/song.mp3',
136
136
  artwork: 'https://example.com/artwork.jpg',
137
+ // Optional custom data (accessible in player state)
138
+ extraPayload: {
139
+ artistId: '123',
140
+ genre: 'Rock',
141
+ isFavorite: true,
142
+ },
137
143
  },
138
144
  ]
139
145
 
@@ -889,6 +895,29 @@ interface TrackItem {
889
895
  duration: number // Duration in seconds
890
896
  url: string // Audio file URL
891
897
  artwork?: string | null // Optional artwork URL
898
+ // key-value pairs for arbitrary data
899
+ extraPayload?: {
900
+ [key: string]: string | number | boolean | Record<string, unknown>
901
+ }
902
+ }
903
+ ```
904
+
905
+ ### Custom Track Metadata (extraPayload)
906
+
907
+ ```typescript
908
+ const track = {
909
+ // ... standard fields
910
+ extraPayload: {
911
+ externalId: 'sp-12345',
912
+ rating: 4.5,
913
+ tags: ['chill', 'instrumental']
914
+ }
915
+ }
916
+
917
+ // Accessing it later
918
+ const { track } = useOnChangeTrack()
919
+ if (track?.extraPayload?.rating > 4) {
920
+ console.log('High rated track playing!')
892
921
  }
893
922
  ```
894
923
 
@@ -370,6 +370,7 @@ class DownloadDatabase private constructor(
370
370
  duration = record.duration,
371
371
  url = record.url,
372
372
  artwork = artworkVariant,
373
+ extraPayload = null,
373
374
  )
374
375
  }
375
376
 
@@ -13,6 +13,8 @@ import org.json.JSONObject
13
13
  import java.util.UUID
14
14
  import java.util.concurrent.CopyOnWriteArrayList
15
15
 
16
+ import com.margelo.nitro.core.AnyMap
17
+
16
18
  /**
17
19
  * Manages multiple playlists using ExoPlayer's native playlist functionality
18
20
  * Based on: https://developer.android.com/media/media3/exoplayer/playlists
@@ -381,6 +383,12 @@ class PlaylistManager private constructor(
381
383
  put("duration", track.duration)
382
384
  put("url", track.url)
383
385
  track.artwork?.let { put("artwork", it) }
386
+ // Serialize extraPayload to JSON for persistence
387
+ track.extraPayload?.let { payload ->
388
+ val extraPayloadMap = payload.toHashMap()
389
+ val extraPayloadJson = JSONObject(extraPayloadMap)
390
+ put("extraPayload", extraPayloadJson)
391
+ }
384
392
  },
385
393
  )
386
394
  }
@@ -420,6 +428,24 @@ class PlaylistManager private constructor(
420
428
  } else {
421
429
  null
422
430
  }
431
+ // Deserialize extraPayload from JSON
432
+ val extraPayload: AnyMap? =
433
+ if (trackObj.has("extraPayload")) {
434
+ val extraPayloadJson = trackObj.getJSONObject("extraPayload")
435
+ val map = AnyMap()
436
+ val keyIterator = extraPayloadJson.keys()
437
+ while (keyIterator.hasNext()) {
438
+ val key = keyIterator.next()
439
+ when (val value = extraPayloadJson.get(key)) {
440
+ is String -> map.setString(key, value)
441
+ is Number -> map.setDouble(key, value.toDouble())
442
+ is Boolean -> map.setBoolean(key, value)
443
+ }
444
+ }
445
+ map
446
+ } else {
447
+ null
448
+ }
423
449
  tracks.add(
424
450
  TrackItem(
425
451
  id = trackObj.getString("id"),
@@ -429,6 +455,7 @@ class PlaylistManager private constructor(
429
455
  duration = trackObj.getDouble("duration"),
430
456
  url = trackObj.getString("url"),
431
457
  artwork = artwork,
458
+ extraPayload = extraPayload,
432
459
  ),
433
460
  )
434
461
  }
@@ -362,7 +362,8 @@ class TrackPlayerCore: NSObject {
362
362
  album: "",
363
363
  duration: 0,
364
364
  url: "",
365
- artwork: nil
365
+ artwork: nil,
366
+ extraPayload: nil
366
367
  ), .end)
367
368
 
368
369
  // Try to play next track
@@ -452,7 +452,8 @@ final class DownloadDatabase {
452
452
  album: record.album,
453
453
  duration: record.duration,
454
454
  url: record.url,
455
- artwork: stringToVariant(record.artwork)
455
+ artwork: stringToVariant(record.artwork),
456
+ extraPayload: nil
456
457
  )
457
458
  }
458
459
 
@@ -595,7 +595,8 @@ final class DownloadManagerCore: NSObject {
595
595
  album: record.album,
596
596
  duration: record.duration,
597
597
  url: record.url,
598
- artwork: artwork
598
+ artwork: artwork,
599
+ extraPayload: nil
599
600
  )
600
601
  }
601
602
 
@@ -377,6 +377,10 @@ class PlaylistManager {
377
377
  } else {
378
378
  trackDict["artwork"] = ""
379
379
  }
380
+ // Serialize extraPayload to dictionary for persistence
381
+ if let extraPayload = track.extraPayload {
382
+ trackDict["extraPayload"] = extraPayload.toDictionary()
383
+ }
380
384
  return trackDict
381
385
  },
382
386
  ]
@@ -425,6 +429,24 @@ class PlaylistManager {
425
429
  let artwork = artworkString.flatMap {
426
430
  !$0.isEmpty ? Variant_NullType_String.second($0) : nil
427
431
  }
432
+
433
+ // Deserialize extraPayload from dictionary
434
+ var extraPayload: AnyMap? = nil
435
+ if let extraPayloadDict = trackDict["extraPayload"] as? [String: Any] {
436
+ extraPayload = AnyMap()
437
+ for (key, value) in extraPayloadDict {
438
+ if let stringValue = value as? String {
439
+ extraPayload?.setString(key: key, value: stringValue)
440
+ } else if let doubleValue = value as? Double {
441
+ extraPayload?.setDouble(key: key, value: doubleValue)
442
+ } else if let intValue = value as? Int {
443
+ extraPayload?.setDouble(key: key, value: Double(intValue))
444
+ } else if let boolValue = value as? Bool {
445
+ extraPayload?.setBoolean(key: key, value: boolValue)
446
+ }
447
+ }
448
+ }
449
+
428
450
  return TrackItem(
429
451
  id: id,
430
452
  title: title,
@@ -432,7 +454,8 @@ class PlaylistManager {
432
454
  album: album,
433
455
  duration: duration,
434
456
  url: url,
435
- artwork: artwork
457
+ artwork: artwork,
458
+ extraPayload: extraPayload
436
459
  )
437
460
  }
438
461
 
@@ -1,3 +1,4 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules';
1
2
  export type CurrentPlayingType = 'playlist' | 'up-next' | 'play-next' | 'not-playing';
2
3
  export interface TrackItem {
3
4
  id: string;
@@ -7,6 +8,7 @@ export interface TrackItem {
7
8
  duration: number;
8
9
  url: string;
9
10
  artwork?: string | null;
11
+ extraPayload?: AnyMap;
10
12
  }
11
13
  export interface Playlist {
12
14
  id: string;
@@ -19,6 +19,8 @@
19
19
  #include "Playlist.hpp"
20
20
  #include "StorageLocation.hpp"
21
21
  #include "TrackItem.hpp"
22
+ #include <NitroModules/AnyMap.hpp>
23
+ #include <NitroModules/JAnyMap.hpp>
22
24
  #include <NitroModules/JNull.hpp>
23
25
  #include <NitroModules/Null.hpp>
24
26
  #include <optional>
@@ -15,6 +15,8 @@
15
15
  #include "JVariant_NullType_String.hpp"
16
16
  #include "StorageLocation.hpp"
17
17
  #include "TrackItem.hpp"
18
+ #include <NitroModules/AnyMap.hpp>
19
+ #include <NitroModules/JAnyMap.hpp>
18
20
  #include <NitroModules/JNull.hpp>
19
21
  #include <NitroModules/Null.hpp>
20
22
  #include <optional>
@@ -22,6 +22,8 @@
22
22
  #include <optional>
23
23
  #include "JVariant_NullType_String.hpp"
24
24
  #include <NitroModules/JNull.hpp>
25
+ #include <NitroModules/AnyMap.hpp>
26
+ #include <NitroModules/JAnyMap.hpp>
25
27
  #include "StorageLocation.hpp"
26
28
  #include "JStorageLocation.hpp"
27
29
 
@@ -21,6 +21,8 @@
21
21
  #include <variant>
22
22
  #include "JVariant_NullType_String.hpp"
23
23
  #include <NitroModules/JNull.hpp>
24
+ #include <NitroModules/AnyMap.hpp>
25
+ #include <NitroModules/JAnyMap.hpp>
24
26
  #include "JReason.hpp"
25
27
 
26
28
  namespace margelo::nitro::nitroplayer {
@@ -24,6 +24,8 @@
24
24
  #include "TrackItem.hpp"
25
25
  #include <vector>
26
26
  #include "JTrackItem.hpp"
27
+ #include <NitroModules/AnyMap.hpp>
28
+ #include <NitroModules/JAnyMap.hpp>
27
29
  #include "JQueueOperation.hpp"
28
30
 
29
31
  namespace margelo::nitro::nitroplayer {
@@ -24,6 +24,8 @@
24
24
  #include <NitroModules/JNull.hpp>
25
25
  #include "TrackItem.hpp"
26
26
  #include "JTrackItem.hpp"
27
+ #include <NitroModules/AnyMap.hpp>
28
+ #include <NitroModules/JAnyMap.hpp>
27
29
  #include "JQueueOperation.hpp"
28
30
 
29
31
  namespace margelo::nitro::nitroplayer {
@@ -69,6 +69,8 @@ namespace margelo::nitro::nitroplayer { enum class PlaybackSource; }
69
69
  #include "JDownloadedTrack.hpp"
70
70
  #include "TrackItem.hpp"
71
71
  #include "JTrackItem.hpp"
72
+ #include <NitroModules/AnyMap.hpp>
73
+ #include <NitroModules/JAnyMap.hpp>
72
74
  #include "DownloadedPlaylist.hpp"
73
75
  #include "JVariant_NullType_DownloadedPlaylist.hpp"
74
76
  #include "JDownloadedPlaylist.hpp"
@@ -26,6 +26,8 @@ namespace margelo::nitro::nitroplayer { enum class QueueOperation; }
26
26
  #include "TrackItem.hpp"
27
27
  #include <vector>
28
28
  #include "JTrackItem.hpp"
29
+ #include <NitroModules/AnyMap.hpp>
30
+ #include <NitroModules/JAnyMap.hpp>
29
31
  #include "QueueOperation.hpp"
30
32
  #include <functional>
31
33
  #include "JFunc_void_std__vector_Playlist__std__optional_QueueOperation_.hpp"
@@ -33,6 +33,8 @@ namespace margelo::nitro::nitroplayer { enum class Reason; }
33
33
  #include <optional>
34
34
  #include "JVariant_NullType_String.hpp"
35
35
  #include <NitroModules/JNull.hpp>
36
+ #include <NitroModules/AnyMap.hpp>
37
+ #include <NitroModules/JAnyMap.hpp>
36
38
  #include "PlayerState.hpp"
37
39
  #include "JPlayerState.hpp"
38
40
  #include "JVariant_NullType_TrackItem.hpp"
@@ -18,6 +18,8 @@
18
18
  #include "JVariant_NullType_TrackItem.hpp"
19
19
  #include "TrackItem.hpp"
20
20
  #include "TrackPlayerState.hpp"
21
+ #include <NitroModules/AnyMap.hpp>
22
+ #include <NitroModules/JAnyMap.hpp>
21
23
  #include <NitroModules/JNull.hpp>
22
24
  #include <NitroModules/Null.hpp>
23
25
  #include <optional>
@@ -13,6 +13,8 @@
13
13
  #include "JTrackItem.hpp"
14
14
  #include "JVariant_NullType_String.hpp"
15
15
  #include "TrackItem.hpp"
16
+ #include <NitroModules/AnyMap.hpp>
17
+ #include <NitroModules/JAnyMap.hpp>
16
18
  #include <NitroModules/JNull.hpp>
17
19
  #include <NitroModules/Null.hpp>
18
20
  #include <optional>
@@ -11,6 +11,8 @@
11
11
  #include "TrackItem.hpp"
12
12
 
13
13
  #include "JVariant_NullType_String.hpp"
14
+ #include <NitroModules/AnyMap.hpp>
15
+ #include <NitroModules/JAnyMap.hpp>
14
16
  #include <NitroModules/JNull.hpp>
15
17
  #include <NitroModules/Null.hpp>
16
18
  #include <optional>
@@ -50,6 +52,8 @@ namespace margelo::nitro::nitroplayer {
50
52
  jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
51
53
  static const auto fieldArtwork = clazz->getField<JVariant_NullType_String>("artwork");
52
54
  jni::local_ref<JVariant_NullType_String> artwork = this->getFieldValue(fieldArtwork);
55
+ static const auto fieldExtraPayload = clazz->getField<JAnyMap::javaobject>("extraPayload");
56
+ jni::local_ref<JAnyMap::javaobject> extraPayload = this->getFieldValue(fieldExtraPayload);
53
57
  return TrackItem(
54
58
  id->toStdString(),
55
59
  title->toStdString(),
@@ -57,7 +61,8 @@ namespace margelo::nitro::nitroplayer {
57
61
  album->toStdString(),
58
62
  duration,
59
63
  url->toStdString(),
60
- artwork != nullptr ? std::make_optional(artwork->toCpp()) : std::nullopt
64
+ artwork != nullptr ? std::make_optional(artwork->toCpp()) : std::nullopt,
65
+ extraPayload != nullptr ? std::make_optional(extraPayload->cthis()->getMap()) : std::nullopt
61
66
  );
62
67
  }
63
68
 
@@ -67,7 +72,7 @@ namespace margelo::nitro::nitroplayer {
67
72
  */
68
73
  [[maybe_unused]]
69
74
  static jni::local_ref<JTrackItem::javaobject> fromCpp(const TrackItem& value) {
70
- using JSignature = JTrackItem(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jni::alias_ref<JVariant_NullType_String>);
75
+ using JSignature = JTrackItem(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jni::alias_ref<JVariant_NullType_String>, jni::alias_ref<JAnyMap::javaobject>);
71
76
  static const auto clazz = javaClassStatic();
72
77
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
73
78
  return create(
@@ -78,7 +83,8 @@ namespace margelo::nitro::nitroplayer {
78
83
  jni::make_jstring(value.album),
79
84
  value.duration,
80
85
  jni::make_jstring(value.url),
81
- value.artwork.has_value() ? JVariant_NullType_String::fromCpp(value.artwork.value()) : nullptr
86
+ value.artwork.has_value() ? JVariant_NullType_String::fromCpp(value.artwork.value()) : nullptr,
87
+ value.extraPayload.has_value() ? JAnyMap::create(value.extraPayload.value()) : nullptr
82
88
  );
83
89
  }
84
90
  };
@@ -23,6 +23,8 @@
23
23
  #include "TrackItem.hpp"
24
24
  #include <vector>
25
25
  #include "JTrackItem.hpp"
26
+ #include <NitroModules/AnyMap.hpp>
27
+ #include <NitroModules/JAnyMap.hpp>
26
28
  #include "DownloadedTrack.hpp"
27
29
  #include "JDownloadedTrack.hpp"
28
30
  #include "StorageLocation.hpp"
@@ -20,6 +20,8 @@
20
20
  #include "JTrackItem.hpp"
21
21
  #include <optional>
22
22
  #include "JVariant_NullType_String.hpp"
23
+ #include <NitroModules/AnyMap.hpp>
24
+ #include <NitroModules/JAnyMap.hpp>
23
25
  #include "StorageLocation.hpp"
24
26
  #include "JStorageLocation.hpp"
25
27
 
@@ -21,6 +21,8 @@
21
21
  #include "TrackItem.hpp"
22
22
  #include <vector>
23
23
  #include "JTrackItem.hpp"
24
+ #include <NitroModules/AnyMap.hpp>
25
+ #include <NitroModules/JAnyMap.hpp>
24
26
 
25
27
  namespace margelo::nitro::nitroplayer {
26
28
 
@@ -18,6 +18,8 @@
18
18
  #include <string>
19
19
  #include <optional>
20
20
  #include "JVariant_NullType_String.hpp"
21
+ #include <NitroModules/AnyMap.hpp>
22
+ #include <NitroModules/JAnyMap.hpp>
21
23
 
22
24
  namespace margelo::nitro::nitroplayer {
23
25
 
@@ -10,6 +10,7 @@ package com.margelo.nitro.nitroplayer
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
12
  import com.margelo.nitro.core.NullType
13
+ import com.margelo.nitro.core.AnyMap
13
14
 
14
15
  /**
15
16
  * Represents the JavaScript object/struct "TrackItem".
@@ -37,7 +38,10 @@ data class TrackItem(
37
38
  val url: String,
38
39
  @DoNotStrip
39
40
  @Keep
40
- val artwork: Variant_NullType_String?
41
+ val artwork: Variant_NullType_String?,
42
+ @DoNotStrip
43
+ @Keep
44
+ val extraPayload: AnyMap?
41
45
  ) {
42
46
  /* primary constructor */
43
47
 
@@ -49,8 +53,8 @@ data class TrackItem(
49
53
  @Keep
50
54
  @Suppress("unused")
51
55
  @JvmStatic
52
- private fun fromCpp(id: String, title: String, artist: String, album: String, duration: Double, url: String, artwork: Variant_NullType_String?): TrackItem {
53
- return TrackItem(id, title, artist, album, duration, url, artwork)
56
+ private fun fromCpp(id: String, title: String, artist: String, album: String, duration: Double, url: String, artwork: Variant_NullType_String?, extraPayload: AnyMap?): TrackItem {
57
+ return TrackItem(id, title, artist, album, duration, url, artwork, extraPayload)
54
58
  }
55
59
  }
56
60
  }
@@ -109,6 +109,7 @@ namespace NitroPlayer { class HybridTrackPlayerSpec_cxx; }
109
109
  #include "StorageLocation.hpp"
110
110
  #include "TrackItem.hpp"
111
111
  #include "TrackPlayerState.hpp"
112
+ #include <NitroModules/AnyMap.hpp>
112
113
  #include <NitroModules/Null.hpp>
113
114
  #include <NitroModules/Promise.hpp>
114
115
  #include <NitroModules/PromiseHolder.hpp>
@@ -293,6 +294,21 @@ namespace margelo::nitro::nitroplayer::bridge::swift {
293
294
  return Func_void_std__exception_ptr_Wrapper(std::move(value));
294
295
  }
295
296
 
297
+ // pragma MARK: std::optional<std::shared_ptr<AnyMap>>
298
+ /**
299
+ * Specialized version of `std::optional<std::shared_ptr<AnyMap>>`.
300
+ */
301
+ using std__optional_std__shared_ptr_AnyMap__ = std::optional<std::shared_ptr<AnyMap>>;
302
+ inline std::optional<std::shared_ptr<AnyMap>> create_std__optional_std__shared_ptr_AnyMap__(const std::shared_ptr<AnyMap>& value) noexcept {
303
+ return std::optional<std::shared_ptr<AnyMap>>(value);
304
+ }
305
+ inline bool has_value_std__optional_std__shared_ptr_AnyMap__(const std::optional<std::shared_ptr<AnyMap>>& optional) noexcept {
306
+ return optional.has_value();
307
+ }
308
+ inline std::shared_ptr<AnyMap> get_std__optional_std__shared_ptr_AnyMap__(const std::optional<std::shared_ptr<AnyMap>>& optional) noexcept {
309
+ return *optional;
310
+ }
311
+
296
312
  // pragma MARK: std::optional<std::string>
297
313
  /**
298
314
  * Specialized version of `std::optional<std::string>`.
@@ -103,6 +103,7 @@ namespace margelo::nitro::nitroplayer { enum class TrackPlayerState; }
103
103
  #include "StorageLocation.hpp"
104
104
  #include "TrackItem.hpp"
105
105
  #include "TrackPlayerState.hpp"
106
+ #include <NitroModules/AnyMap.hpp>
106
107
  #include <NitroModules/Null.hpp>
107
108
  #include <NitroModules/Promise.hpp>
108
109
  #include <NitroModules/Result.hpp>
@@ -49,6 +49,7 @@ namespace margelo::nitro::nitroplayer { enum class PlaybackSource; }
49
49
  #include <variant>
50
50
  #include <NitroModules/Promise.hpp>
51
51
  #include "TrackItem.hpp"
52
+ #include <NitroModules/AnyMap.hpp>
52
53
  #include <vector>
53
54
  #include "DownloadTask.hpp"
54
55
  #include "DownloadState.hpp"
@@ -26,6 +26,7 @@ namespace margelo::nitro::nitroplayer { enum class QueueOperation; }
26
26
  #include <variant>
27
27
  #include "TrackItem.hpp"
28
28
  #include <vector>
29
+ #include <NitroModules/AnyMap.hpp>
29
30
  #include "QueueOperation.hpp"
30
31
  #include <functional>
31
32
 
@@ -34,6 +34,7 @@ namespace margelo::nitro::nitroplayer { enum class Reason; }
34
34
  #include <vector>
35
35
  #include <NitroModules/Null.hpp>
36
36
  #include <variant>
37
+ #include <NitroModules/AnyMap.hpp>
37
38
  #include "PlayerState.hpp"
38
39
  #include "TrackPlayerState.hpp"
39
40
  #include "CurrentPlayingType.hpp"
@@ -19,7 +19,7 @@ public extension TrackItem {
19
19
  /**
20
20
  * Create a new instance of `TrackItem`.
21
21
  */
22
- init(id: String, title: String, artist: String, album: String, duration: Double, url: String, artwork: Variant_NullType_String?) {
22
+ init(id: String, title: String, artist: String, album: String, duration: Double, url: String, artwork: Variant_NullType_String?, extraPayload: AnyMap?) {
23
23
  self.init(std.string(id), std.string(title), std.string(artist), std.string(album), duration, std.string(url), { () -> bridge.std__optional_std__variant_nitro__NullType__std__string__ in
24
24
  if let __unwrappedValue = artwork {
25
25
  return bridge.create_std__optional_std__variant_nitro__NullType__std__string__({ () -> bridge.std__variant_nitro__NullType__std__string_ in
@@ -33,6 +33,12 @@ public extension TrackItem {
33
33
  } else {
34
34
  return .init()
35
35
  }
36
+ }(), { () -> bridge.std__optional_std__shared_ptr_AnyMap__ in
37
+ if let __unwrappedValue = extraPayload {
38
+ return bridge.create_std__optional_std__shared_ptr_AnyMap__(__unwrappedValue.cppPart)
39
+ } else {
40
+ return .init()
41
+ }
36
42
  }())
37
43
  }
38
44
 
@@ -144,4 +150,28 @@ public extension TrackItem {
144
150
  }()
145
151
  }
146
152
  }
153
+
154
+ var extraPayload: AnyMap? {
155
+ @inline(__always)
156
+ get {
157
+ return { () -> AnyMap? in
158
+ if bridge.has_value_std__optional_std__shared_ptr_AnyMap__(self.__extraPayload) {
159
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_AnyMap__(self.__extraPayload)
160
+ return AnyMap(withCppPart: __unwrapped)
161
+ } else {
162
+ return nil
163
+ }
164
+ }()
165
+ }
166
+ @inline(__always)
167
+ set {
168
+ self.__extraPayload = { () -> bridge.std__optional_std__shared_ptr_AnyMap__ in
169
+ if let __unwrappedValue = newValue {
170
+ return bridge.create_std__optional_std__shared_ptr_AnyMap__(__unwrappedValue.cppPart)
171
+ } else {
172
+ return .init()
173
+ }
174
+ }()
175
+ }
176
+ }
147
177
  }
@@ -29,6 +29,7 @@
29
29
  #include <NitroModules/Null.hpp>
30
30
  #include <variant>
31
31
  #include <optional>
32
+ #include <NitroModules/AnyMap.hpp>
32
33
 
33
34
  namespace margelo::nitro::nitroplayer {
34
35
 
@@ -44,10 +45,11 @@ namespace margelo::nitro::nitroplayer {
44
45
  double duration SWIFT_PRIVATE;
45
46
  std::string url SWIFT_PRIVATE;
46
47
  std::optional<std::variant<nitro::NullType, std::string>> artwork SWIFT_PRIVATE;
48
+ std::optional<std::shared_ptr<AnyMap>> extraPayload SWIFT_PRIVATE;
47
49
 
48
50
  public:
49
51
  TrackItem() = default;
50
- explicit TrackItem(std::string id, std::string title, std::string artist, std::string album, double duration, std::string url, std::optional<std::variant<nitro::NullType, std::string>> artwork): id(id), title(title), artist(artist), album(album), duration(duration), url(url), artwork(artwork) {}
52
+ explicit TrackItem(std::string id, std::string title, std::string artist, std::string album, double duration, std::string url, std::optional<std::variant<nitro::NullType, std::string>> artwork, std::optional<std::shared_ptr<AnyMap>> extraPayload): id(id), title(title), artist(artist), album(album), duration(duration), url(url), artwork(artwork), extraPayload(extraPayload) {}
51
53
  };
52
54
 
53
55
  } // namespace margelo::nitro::nitroplayer
@@ -66,7 +68,8 @@ namespace margelo::nitro {
66
68
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "album")),
67
69
  JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "duration")),
68
70
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "url")),
69
- JSIConverter<std::optional<std::variant<nitro::NullType, std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "artwork"))
71
+ JSIConverter<std::optional<std::variant<nitro::NullType, std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "artwork")),
72
+ JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::fromJSI(runtime, obj.getProperty(runtime, "extraPayload"))
70
73
  );
71
74
  }
72
75
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitroplayer::TrackItem& arg) {
@@ -78,6 +81,7 @@ namespace margelo::nitro {
78
81
  obj.setProperty(runtime, "duration", JSIConverter<double>::toJSI(runtime, arg.duration));
79
82
  obj.setProperty(runtime, "url", JSIConverter<std::string>::toJSI(runtime, arg.url));
80
83
  obj.setProperty(runtime, "artwork", JSIConverter<std::optional<std::variant<nitro::NullType, std::string>>>::toJSI(runtime, arg.artwork));
84
+ obj.setProperty(runtime, "extraPayload", JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::toJSI(runtime, arg.extraPayload));
81
85
  return obj;
82
86
  }
83
87
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -95,6 +99,7 @@ namespace margelo::nitro {
95
99
  if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "duration"))) return false;
96
100
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "url"))) return false;
97
101
  if (!JSIConverter<std::optional<std::variant<nitro::NullType, std::string>>>::canConvert(runtime, obj.getProperty(runtime, "artwork"))) return false;
102
+ if (!JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::canConvert(runtime, obj.getProperty(runtime, "extraPayload"))) return false;
98
103
  return true;
99
104
  }
100
105
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-player",
3
- "version": "0.3.0-alpha.15",
3
+ "version": "0.3.0-alpha.17",
4
4
  "description": "react-native-nitro-player",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -1,3 +1,5 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules'
2
+
1
3
  export type CurrentPlayingType =
2
4
  | 'playlist'
3
5
  | 'up-next'
@@ -11,6 +13,7 @@ export interface TrackItem {
11
13
  duration: number
12
14
  url: string
13
15
  artwork?: string | null
16
+ extraPayload?: AnyMap
14
17
  }
15
18
 
16
19
  export interface Playlist {