react-native-queue-player 1.0.7 → 1.0.8

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 (49) hide show
  1. package/android/src/main/java/com/margelo/nitro/queueplayer/TrackPlayer.kt +39 -0
  2. package/android/src/test/java/com/margelo/nitro/queueplayer/TrackPlayerQueueChangeTest.kt +180 -0
  3. package/ios/AVQueueBuilder.swift +29 -0
  4. package/ios/QueueState.swift +14 -2
  5. package/ios/Tests/AVQueueBuilderTests.swift +74 -0
  6. package/ios/Tests/QueueStateTests.swift +50 -0
  7. package/ios/TrackPlayer.swift +121 -14
  8. package/lib/module/hooks/index.js +1 -0
  9. package/lib/module/hooks/index.js.map +1 -1
  10. package/lib/module/hooks/useQueue.js +57 -0
  11. package/lib/module/hooks/useQueue.js.map +1 -0
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/types.js +7 -0
  14. package/lib/module/types.js.map +1 -1
  15. package/lib/typescript/TrackPlayer.nitro.d.ts +27 -1
  16. package/lib/typescript/TrackPlayer.nitro.d.ts.map +1 -1
  17. package/lib/typescript/hooks/index.d.ts +2 -0
  18. package/lib/typescript/hooks/index.d.ts.map +1 -1
  19. package/lib/typescript/hooks/useQueue.d.ts +20 -0
  20. package/lib/typescript/hooks/useQueue.d.ts.map +1 -0
  21. package/lib/typescript/index.d.ts +1 -1
  22. package/lib/typescript/index.d.ts.map +1 -1
  23. package/lib/typescript/types.d.ts +5 -0
  24. package/lib/typescript/types.d.ts.map +1 -1
  25. package/nitrogen/generated/android/c++/JFunc_void_std__vector_TrackItem__double_QueueChangeReason.hpp +101 -0
  26. package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.cpp +18 -0
  27. package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.hpp +1 -0
  28. package/nitrogen/generated/android/c++/JQueueChangeReason.hpp +70 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/queueplayer/Func_void_std__vector_TrackItem__double_QueueChangeReason.kt +80 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/queueplayer/HybridTrackPlayerSpec.kt +9 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/queueplayer/QueueChangeReason.kt +27 -0
  32. package/nitrogen/generated/android/queueplayerOnLoad.cpp +2 -0
  33. package/nitrogen/generated/ios/QueuePlayer-Swift-Cxx-Bridge.cpp +8 -0
  34. package/nitrogen/generated/ios/QueuePlayer-Swift-Cxx-Bridge.hpp +25 -0
  35. package/nitrogen/generated/ios/QueuePlayer-Swift-Cxx-Umbrella.hpp +3 -0
  36. package/nitrogen/generated/ios/c++/HybridTrackPlayerSpecSwift.hpp +11 -0
  37. package/nitrogen/generated/ios/swift/Func_void_std__vector_TrackItem__double_QueueChangeReason.swift +46 -0
  38. package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec.swift +1 -0
  39. package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec_cxx.swift +26 -0
  40. package/nitrogen/generated/ios/swift/QueueChangeReason.swift +56 -0
  41. package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.cpp +1 -0
  42. package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.hpp +4 -0
  43. package/nitrogen/generated/shared/c++/QueueChangeReason.hpp +92 -0
  44. package/package.json +1 -1
  45. package/src/TrackPlayer.nitro.ts +33 -0
  46. package/src/hooks/index.ts +3 -0
  47. package/src/hooks/useQueue.ts +56 -0
  48. package/src/index.ts +1 -0
  49. package/src/types.ts +12 -0
@@ -0,0 +1,101 @@
1
+ ///
2
+ /// JFunc_void_std__vector_TrackItem__double_QueueChangeReason.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "TrackItem.hpp"
14
+ #include <vector>
15
+ #include "QueueChangeReason.hpp"
16
+ #include <functional>
17
+ #include <NitroModules/JNICallable.hpp>
18
+ #include "JTrackItem.hpp"
19
+ #include <string>
20
+ #include <optional>
21
+ #include <unordered_map>
22
+ #include "JQueueChangeReason.hpp"
23
+
24
+ namespace margelo::nitro::queueplayer {
25
+
26
+ using namespace facebook;
27
+
28
+ /**
29
+ * Represents the Java/Kotlin callback `(queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason) -> Unit`.
30
+ * This can be passed around between C++ and Java/Kotlin.
31
+ */
32
+ struct JFunc_void_std__vector_TrackItem__double_QueueChangeReason: public jni::JavaClass<JFunc_void_std__vector_TrackItem__double_QueueChangeReason> {
33
+ public:
34
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/queueplayer/Func_void_std__vector_TrackItem__double_QueueChangeReason;";
35
+
36
+ public:
37
+ /**
38
+ * Invokes the function this `JFunc_void_std__vector_TrackItem__double_QueueChangeReason` instance holds through JNI.
39
+ */
40
+ void invoke(const std::vector<TrackItem>& queue, double currentIndex, QueueChangeReason reason) const {
41
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<JTrackItem>> /* queue */, double /* currentIndex */, jni::alias_ref<JQueueChangeReason> /* reason */)>("invoke");
42
+ method(self(), [&](auto&& __input) {
43
+ size_t __size = __input.size();
44
+ jni::local_ref<jni::JArrayClass<JTrackItem>> __array = jni::JArrayClass<JTrackItem>::newArray(__size);
45
+ for (size_t __i = 0; __i < __size; __i++) {
46
+ const auto& __element = __input[__i];
47
+ auto __elementJni = JTrackItem::fromCpp(__element);
48
+ __array->setElement(__i, *__elementJni);
49
+ }
50
+ return __array;
51
+ }(queue), currentIndex, JQueueChangeReason::fromCpp(reason));
52
+ }
53
+ };
54
+
55
+ /**
56
+ * An implementation of Func_void_std__vector_TrackItem__double_QueueChangeReason that is backed by a C++ implementation (using `std::function<...>`)
57
+ */
58
+ class JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx final: public jni::HybridClass<JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx, JFunc_void_std__vector_TrackItem__double_QueueChangeReason> {
59
+ public:
60
+ static jni::local_ref<JFunc_void_std__vector_TrackItem__double_QueueChangeReason::javaobject> fromCpp(const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& func) {
61
+ return JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx::newObjectCxxArgs(func);
62
+ }
63
+
64
+ public:
65
+ /**
66
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx` instance holds.
67
+ */
68
+ void invoke_cxx(jni::alias_ref<jni::JArrayClass<JTrackItem>> queue, double currentIndex, jni::alias_ref<JQueueChangeReason> reason) {
69
+ _func([&](auto&& __input) {
70
+ size_t __size = __input->size();
71
+ std::vector<TrackItem> __vector;
72
+ __vector.reserve(__size);
73
+ for (size_t __i = 0; __i < __size; __i++) {
74
+ auto __element = __input->getElement(__i);
75
+ __vector.push_back(__element->toCpp());
76
+ }
77
+ return __vector;
78
+ }(queue), currentIndex, reason->toCpp());
79
+ }
80
+
81
+ public:
82
+ [[nodiscard]]
83
+ inline const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& getFunction() const {
84
+ return _func;
85
+ }
86
+
87
+ public:
88
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/queueplayer/Func_void_std__vector_TrackItem__double_QueueChangeReason_cxx;";
89
+ static void registerNatives() {
90
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx::invoke_cxx)});
91
+ }
92
+
93
+ private:
94
+ explicit JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx(const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& func): _func(func) { }
95
+
96
+ private:
97
+ friend HybridBase;
98
+ std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)> _func;
99
+ };
100
+
101
+ } // namespace margelo::nitro::queueplayer
@@ -59,6 +59,8 @@ namespace margelo::nitro::queueplayer { enum class RepeatMode; }
59
59
  namespace margelo::nitro::queueplayer { enum class StateChangeReason; }
60
60
  // Forward declaration of `TrackChangeReason` to properly resolve imports.
61
61
  namespace margelo::nitro::queueplayer { enum class TrackChangeReason; }
62
+ // Forward declaration of `QueueChangeReason` to properly resolve imports.
63
+ namespace margelo::nitro::queueplayer { enum class QueueChangeReason; }
62
64
  // Forward declaration of `PlayerProgress` to properly resolve imports.
63
65
  namespace margelo::nitro::queueplayer { struct PlayerProgress; }
64
66
  // Forward declaration of `PlaybackError` to properly resolve imports.
@@ -164,6 +166,9 @@ namespace margelo::nitro::queueplayer { struct LookaheadCacheConfig; }
164
166
  #include "TrackChangeReason.hpp"
165
167
  #include "JFunc_void_std__optional_TrackItem__double_TrackChangeReason_std__optional_double_.hpp"
166
168
  #include "JTrackChangeReason.hpp"
169
+ #include "QueueChangeReason.hpp"
170
+ #include "JFunc_void_std__vector_TrackItem__double_QueueChangeReason.hpp"
171
+ #include "JQueueChangeReason.hpp"
167
172
  #include "PlayerProgress.hpp"
168
173
  #include "JFunc_void_PlayerProgress.hpp"
169
174
  #include "JPlayerProgress.hpp"
@@ -759,6 +764,19 @@ namespace margelo::nitro::queueplayer {
759
764
  }
760
765
  }();
761
766
  }
767
+ std::function<void()> JHybridTrackPlayerSpec::onQueueChange(const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& callback) {
768
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_std__vector_TrackItem__double_QueueChangeReason::javaobject> /* callback */)>("onQueueChange_cxx");
769
+ auto __result = method(_javaPart, JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx::fromCpp(callback));
770
+ return [&]() -> std::function<void()> {
771
+ if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
772
+ auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
773
+ return downcast->cthis()->getFunction();
774
+ } else {
775
+ auto __resultRef = jni::make_global(__result);
776
+ return JNICallable<JFunc_void, void()>(std::move(__resultRef));
777
+ }
778
+ }();
779
+ }
762
780
  std::function<void()> JHybridTrackPlayerSpec::onProgress(const std::function<void(const PlayerProgress& /* progress */)>& callback) {
763
781
  static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_PlayerProgress::javaobject> /* callback */)>("onProgress_cxx");
764
782
  auto __result = method(_javaPart, JFunc_void_PlayerProgress_cxx::fromCpp(callback));
@@ -97,6 +97,7 @@ namespace margelo::nitro::queueplayer {
97
97
  SleepTimerState getSleepTimer() override;
98
98
  std::function<void()> onStateChange(const std::function<void(PlayerState /* state */, StateChangeReason /* reason */)>& callback) override;
99
99
  std::function<void()> onTrackChange(const std::function<void(const std::optional<TrackItem>& /* track */, double /* index */, TrackChangeReason /* reason */, std::optional<double> /* transitionGapMs */)>& callback) override;
100
+ std::function<void()> onQueueChange(const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& callback) override;
100
101
  std::function<void()> onProgress(const std::function<void(const PlayerProgress& /* progress */)>& callback) override;
101
102
  std::function<void()> onPlaybackMilestone(const std::function<void(double /* milestone */, double /* trackIndex */)>& callback) override;
102
103
  std::function<void()> onError(const std::function<void(const PlaybackError& /* error */)>& callback) override;
@@ -0,0 +1,70 @@
1
+ ///
2
+ /// JQueueChangeReason.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "QueueChangeReason.hpp"
12
+
13
+ namespace margelo::nitro::queueplayer {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "QueueChangeReason" and the Kotlin enum "QueueChangeReason".
19
+ */
20
+ struct JQueueChangeReason final: public jni::JavaClass<JQueueChangeReason> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/queueplayer/QueueChangeReason;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum QueueChangeReason.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ QueueChangeReason toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<QueueChangeReason>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JQueueChangeReason> fromCpp(QueueChangeReason value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case QueueChangeReason::SET_QUEUE:
46
+ static const auto fieldSET_QUEUE = clazz->getStaticField<JQueueChangeReason>("SET_QUEUE");
47
+ return clazz->getStaticFieldValue(fieldSET_QUEUE);
48
+ case QueueChangeReason::ADD:
49
+ static const auto fieldADD = clazz->getStaticField<JQueueChangeReason>("ADD");
50
+ return clazz->getStaticFieldValue(fieldADD);
51
+ case QueueChangeReason::REMOVE:
52
+ static const auto fieldREMOVE = clazz->getStaticField<JQueueChangeReason>("REMOVE");
53
+ return clazz->getStaticFieldValue(fieldREMOVE);
54
+ case QueueChangeReason::MOVE:
55
+ static const auto fieldMOVE = clazz->getStaticField<JQueueChangeReason>("MOVE");
56
+ return clazz->getStaticFieldValue(fieldMOVE);
57
+ case QueueChangeReason::CLEAR:
58
+ static const auto fieldCLEAR = clazz->getStaticField<JQueueChangeReason>("CLEAR");
59
+ return clazz->getStaticFieldValue(fieldCLEAR);
60
+ case QueueChangeReason::SHUFFLE:
61
+ static const auto fieldSHUFFLE = clazz->getStaticField<JQueueChangeReason>("SHUFFLE");
62
+ return clazz->getStaticFieldValue(fieldSHUFFLE);
63
+ default:
64
+ std::string stringValue = std::to_string(static_cast<int>(value));
65
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
66
+ }
67
+ }
68
+ };
69
+
70
+ } // namespace margelo::nitro::queueplayer
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_std__vector_TrackItem__double_QueueChangeReason.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.queueplayer
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
14
+
15
+
16
+ /**
17
+ * Represents the JavaScript callback `(queue: array, currentIndex: number, reason: enum) => void`.
18
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
19
+ * or in Kotlin/Java (in which case it is a native callback).
20
+ */
21
+ @DoNotStrip
22
+ @Keep
23
+ @Suppress("ClassName", "RedundantUnitReturnType")
24
+ fun interface Func_void_std__vector_TrackItem__double_QueueChangeReason: (Array<TrackItem>, Double, QueueChangeReason) -> Unit {
25
+ /**
26
+ * Call the given JS callback.
27
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
28
+ */
29
+ @DoNotStrip
30
+ @Keep
31
+ override fun invoke(queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(queue: array, currentIndex: number, reason: enum) => void`.
36
+ * This is implemented in C++, via a `std::function<...>`.
37
+ * The callback might be coming from JS.
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress(
42
+ "KotlinJniMissingFunction", "unused",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
+ )
46
+ class Func_void_std__vector_TrackItem__double_QueueChangeReason_cxx: Func_void_std__vector_TrackItem__double_QueueChangeReason {
47
+ @DoNotStrip
48
+ @Keep
49
+ private val mHybridData: HybridData
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private constructor(hybridData: HybridData) {
54
+ mHybridData = hybridData
55
+ }
56
+
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason): Unit
60
+ = invoke_cxx(queue,currentIndex,reason)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(queue: array, currentIndex: number, reason: enum) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(Array<TrackItem>, Double, QueueChangeReason) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_std__vector_TrackItem__double_QueueChangeReason_java(private val function: (Array<TrackItem>, Double, QueueChangeReason) -> Unit): Func_void_std__vector_TrackItem__double_QueueChangeReason {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason): Unit {
78
+ return this.function(queue, currentIndex, reason)
79
+ }
80
+ }
@@ -212,6 +212,15 @@ abstract class HybridTrackPlayerSpec: HybridObject() {
212
212
  return Func_void_java(__result)
213
213
  }
214
214
 
215
+ abstract fun onQueueChange(callback: (queue: Array<TrackItem>, currentIndex: Double, reason: QueueChangeReason) -> Unit): () -> Unit
216
+
217
+ @DoNotStrip
218
+ @Keep
219
+ private fun onQueueChange_cxx(callback: Func_void_std__vector_TrackItem__double_QueueChangeReason): Func_void {
220
+ val __result = onQueueChange(callback)
221
+ return Func_void_java(__result)
222
+ }
223
+
215
224
  abstract fun onProgress(callback: (progress: PlayerProgress) -> Unit): () -> Unit
216
225
 
217
226
  @DoNotStrip
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// QueueChangeReason.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.queueplayer
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "QueueChangeReason".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class QueueChangeReason(@DoNotStrip @Keep val value: Int) {
19
+ SET_QUEUE(0),
20
+ ADD(1),
21
+ REMOVE(2),
22
+ MOVE(3),
23
+ CLEAR(4),
24
+ SHUFFLE(5);
25
+
26
+ companion object
27
+ }
@@ -29,6 +29,7 @@
29
29
  #include "JHybridTrackPlayerSpec.hpp"
30
30
  #include "JFunc_void_PlayerState_StateChangeReason.hpp"
31
31
  #include "JFunc_void_std__optional_TrackItem__double_TrackChangeReason_std__optional_double_.hpp"
32
+ #include "JFunc_void_std__vector_TrackItem__double_QueueChangeReason.hpp"
32
33
  #include "JFunc_void_PlayerProgress.hpp"
33
34
  #include "JFunc_void_double_double.hpp"
34
35
  #include "JFunc_void_PlaybackError.hpp"
@@ -106,6 +107,7 @@ void registerAllNatives() {
106
107
  margelo::nitro::queueplayer::JHybridTrackPlayerSpec::CxxPart::registerNatives();
107
108
  margelo::nitro::queueplayer::JFunc_void_PlayerState_StateChangeReason_cxx::registerNatives();
108
109
  margelo::nitro::queueplayer::JFunc_void_std__optional_TrackItem__double_TrackChangeReason_std__optional_double__cxx::registerNatives();
110
+ margelo::nitro::queueplayer::JFunc_void_std__vector_TrackItem__double_QueueChangeReason_cxx::registerNatives();
109
111
  margelo::nitro::queueplayer::JFunc_void_PlayerProgress_cxx::registerNatives();
110
112
  margelo::nitro::queueplayer::JFunc_void_double_double_cxx::registerNatives();
111
113
  margelo::nitro::queueplayer::JFunc_void_PlaybackError_cxx::registerNatives();
@@ -161,6 +161,14 @@ namespace margelo::nitro::queueplayer::bridge::swift {
161
161
  };
162
162
  }
163
163
 
164
+ // pragma MARK: std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>
165
+ Func_void_std__vector_TrackItem__double_QueueChangeReason create_Func_void_std__vector_TrackItem__double_QueueChangeReason(void* NON_NULL swiftClosureWrapper) noexcept {
166
+ auto swiftClosure = QueuePlayer::Func_void_std__vector_TrackItem__double_QueueChangeReason::fromUnsafe(swiftClosureWrapper);
167
+ return [swiftClosure = std::move(swiftClosure)](const std::vector<TrackItem>& queue, double currentIndex, QueueChangeReason reason) mutable -> void {
168
+ swiftClosure.call(queue, currentIndex, static_cast<int>(reason));
169
+ };
170
+ }
171
+
164
172
  // pragma MARK: std::function<void(const PlayerProgress& /* progress */)>
165
173
  Func_void_PlayerProgress create_Func_void_PlayerProgress(void* NON_NULL swiftClosureWrapper) noexcept {
166
174
  auto swiftClosure = QueuePlayer::Func_void_PlayerProgress::fromUnsafe(swiftClosureWrapper);
@@ -98,6 +98,8 @@ namespace margelo::nitro::queueplayer { struct PlaybackMode; }
98
98
  namespace margelo::nitro::queueplayer { struct PlayerProgress; }
99
99
  // Forward declaration of `PlayerState` to properly resolve imports.
100
100
  namespace margelo::nitro::queueplayer { enum class PlayerState; }
101
+ // Forward declaration of `QueueChangeReason` to properly resolve imports.
102
+ namespace margelo::nitro::queueplayer { enum class QueueChangeReason; }
101
103
  // Forward declaration of `RemoteControlOptions` to properly resolve imports.
102
104
  namespace margelo::nitro::queueplayer { struct RemoteControlOptions; }
103
105
  // Forward declaration of `ReplayGainMode` to properly resolve imports.
@@ -180,6 +182,7 @@ namespace QueuePlayer { class HybridVisualizerSpec_cxx; }
180
182
  #include "PlaybackMode.hpp"
181
183
  #include "PlayerProgress.hpp"
182
184
  #include "PlayerState.hpp"
185
+ #include "QueueChangeReason.hpp"
183
186
  #include "RemoteControlOptions.hpp"
184
187
  #include "ReplayGainMode.hpp"
185
188
  #include "SectionIcon.hpp"
@@ -916,6 +919,28 @@ namespace margelo::nitro::queueplayer::bridge::swift {
916
919
  return Func_void_std__optional_TrackItem__double_TrackChangeReason_std__optional_double__Wrapper(std::move(value));
917
920
  }
918
921
 
922
+ // pragma MARK: std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>
923
+ /**
924
+ * Specialized version of `std::function<void(const std::vector<TrackItem>&, double, QueueChangeReason)>`.
925
+ */
926
+ using Func_void_std__vector_TrackItem__double_QueueChangeReason = std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>;
927
+ /**
928
+ * Wrapper class for a `std::function<void(const std::vector<TrackItem>& / * queue * /, double / * currentIndex * /, QueueChangeReason / * reason * /)>`, this can be used from Swift.
929
+ */
930
+ class Func_void_std__vector_TrackItem__double_QueueChangeReason_Wrapper final {
931
+ public:
932
+ explicit Func_void_std__vector_TrackItem__double_QueueChangeReason_Wrapper(std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>&& func): _function(std::make_unique<std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>>(std::move(func))) {}
933
+ inline void call(std::vector<TrackItem> queue, double currentIndex, int reason) const noexcept {
934
+ _function->operator()(queue, currentIndex, static_cast<QueueChangeReason>(reason));
935
+ }
936
+ private:
937
+ std::unique_ptr<std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>> _function;
938
+ } SWIFT_NONCOPYABLE;
939
+ Func_void_std__vector_TrackItem__double_QueueChangeReason create_Func_void_std__vector_TrackItem__double_QueueChangeReason(void* NON_NULL swiftClosureWrapper) noexcept;
940
+ inline Func_void_std__vector_TrackItem__double_QueueChangeReason_Wrapper wrap_Func_void_std__vector_TrackItem__double_QueueChangeReason(Func_void_std__vector_TrackItem__double_QueueChangeReason value) noexcept {
941
+ return Func_void_std__vector_TrackItem__double_QueueChangeReason_Wrapper(std::move(value));
942
+ }
943
+
919
944
  // pragma MARK: std::function<void(const PlayerProgress& /* progress */)>
920
945
  /**
921
946
  * Specialized version of `std::function<void(const PlayerProgress&)>`.
@@ -108,6 +108,8 @@ namespace margelo::nitro::queueplayer { struct PlayerConfig; }
108
108
  namespace margelo::nitro::queueplayer { struct PlayerProgress; }
109
109
  // Forward declaration of `PlayerState` to properly resolve imports.
110
110
  namespace margelo::nitro::queueplayer { enum class PlayerState; }
111
+ // Forward declaration of `QueueChangeReason` to properly resolve imports.
112
+ namespace margelo::nitro::queueplayer { enum class QueueChangeReason; }
111
113
  // Forward declaration of `RemoteControlOptions` to properly resolve imports.
112
114
  namespace margelo::nitro::queueplayer { struct RemoteControlOptions; }
113
115
  // Forward declaration of `RemoteSkipMode` to properly resolve imports.
@@ -194,6 +196,7 @@ namespace margelo::nitro::queueplayer { struct VoiceVocabulary; }
194
196
  #include "PlayerConfig.hpp"
195
197
  #include "PlayerProgress.hpp"
196
198
  #include "PlayerState.hpp"
199
+ #include "QueueChangeReason.hpp"
197
200
  #include "RemoteControlOptions.hpp"
198
201
  #include "RemoteSkipMode.hpp"
199
202
  #include "RepeatMode.hpp"
@@ -50,6 +50,8 @@ namespace margelo::nitro::queueplayer { struct SleepTimerState; }
50
50
  namespace margelo::nitro::queueplayer { enum class StateChangeReason; }
51
51
  // Forward declaration of `TrackChangeReason` to properly resolve imports.
52
52
  namespace margelo::nitro::queueplayer { enum class TrackChangeReason; }
53
+ // Forward declaration of `QueueChangeReason` to properly resolve imports.
54
+ namespace margelo::nitro::queueplayer { enum class QueueChangeReason; }
53
55
  // Forward declaration of `PlayerProgress` to properly resolve imports.
54
56
  namespace margelo::nitro::queueplayer { struct PlayerProgress; }
55
57
  // Forward declaration of `PlaybackError` to properly resolve imports.
@@ -124,6 +126,7 @@ namespace margelo::nitro::queueplayer { struct NowPlayingFormatAndroidExtras; }
124
126
  #include <functional>
125
127
  #include "StateChangeReason.hpp"
126
128
  #include "TrackChangeReason.hpp"
129
+ #include "QueueChangeReason.hpp"
127
130
  #include "PlayerProgress.hpp"
128
131
  #include "PlaybackError.hpp"
129
132
  #include "PlaybackErrorCode.hpp"
@@ -545,6 +548,14 @@ namespace margelo::nitro::queueplayer {
545
548
  auto __value = std::move(__result.value());
546
549
  return __value;
547
550
  }
551
+ inline std::function<void()> onQueueChange(const std::function<void(const std::vector<TrackItem>& /* queue */, double /* currentIndex */, QueueChangeReason /* reason */)>& callback) override {
552
+ auto __result = _swiftPart.onQueueChange(callback);
553
+ if (__result.hasError()) [[unlikely]] {
554
+ std::rethrow_exception(__result.error());
555
+ }
556
+ auto __value = std::move(__result.value());
557
+ return __value;
558
+ }
548
559
  inline std::function<void()> onProgress(const std::function<void(const PlayerProgress& /* progress */)>& callback) override {
549
560
  auto __result = _swiftPart.onProgress(callback);
550
561
  if (__result.hasError()) [[unlikely]] {
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_std__vector_TrackItem__double_QueueChangeReason.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ queue: [TrackItem], _ currentIndex: Double, _ reason: QueueChangeReason) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__vector_TrackItem__double_QueueChangeReason {
15
+ public typealias bridge = margelo.nitro.queueplayer.bridge.swift
16
+
17
+ private let closure: (_ queue: [TrackItem], _ currentIndex: Double, _ reason: QueueChangeReason) -> Void
18
+
19
+ public init(_ closure: @escaping (_ queue: [TrackItem], _ currentIndex: Double, _ reason: QueueChangeReason) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(queue: bridge.std__vector_TrackItem_, currentIndex: Double, reason: Int32) -> Void {
25
+ self.closure(queue.map({ __item in __item }), currentIndex, margelo.nitro.queueplayer.QueueChangeReason(rawValue: reason)!)
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_std__vector_TrackItem__double_QueueChangeReason`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_TrackItem__double_QueueChangeReason>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_TrackItem__double_QueueChangeReason {
44
+ return Unmanaged<Func_void_std__vector_TrackItem__double_QueueChangeReason>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -56,6 +56,7 @@ public protocol HybridTrackPlayerSpec_protocol: HybridObject {
56
56
  func getSleepTimer() throws -> SleepTimerState
57
57
  func onStateChange(callback: @escaping (_ state: PlayerState, _ reason: StateChangeReason) -> Void) throws -> () -> Void
58
58
  func onTrackChange(callback: @escaping (_ track: TrackItem?, _ index: Double, _ reason: TrackChangeReason, _ transitionGapMs: Double?) -> Void) throws -> () -> Void
59
+ func onQueueChange(callback: @escaping (_ queue: [TrackItem], _ currentIndex: Double, _ reason: QueueChangeReason) -> Void) throws -> () -> Void
59
60
  func onProgress(callback: @escaping (_ progress: PlayerProgress) -> Void) throws -> () -> Void
60
61
  func onPlaybackMilestone(callback: @escaping (_ milestone: Double, _ trackIndex: Double) -> Void) throws -> () -> Void
61
62
  func onError(callback: @escaping (_ error: PlaybackError) -> Void) throws -> () -> Void
@@ -869,6 +869,32 @@ open class HybridTrackPlayerSpec_cxx {
869
869
  }
870
870
  }
871
871
 
872
+ @inline(__always)
873
+ public final func onQueueChange(callback: bridge.Func_void_std__vector_TrackItem__double_QueueChangeReason) -> bridge.Result_std__function_void____ {
874
+ do {
875
+ let __result = try self.__implementation.onQueueChange(callback: { () -> ([TrackItem], Double, QueueChangeReason) -> Void in
876
+ let __wrappedFunction = bridge.wrap_Func_void_std__vector_TrackItem__double_QueueChangeReason(callback)
877
+ return { (__queue: [TrackItem], __currentIndex: Double, __reason: QueueChangeReason) -> Void in
878
+ __wrappedFunction.call({ () -> bridge.std__vector_TrackItem_ in
879
+ var __vector = bridge.create_std__vector_TrackItem_(__queue.count)
880
+ for __item in __queue {
881
+ __vector.push_back(__item)
882
+ }
883
+ return __vector
884
+ }(), __currentIndex, __reason.rawValue)
885
+ }
886
+ }())
887
+ let __resultCpp = { () -> bridge.Func_void in
888
+ let __closureWrapper = Func_void(__result)
889
+ return bridge.create_Func_void(__closureWrapper.toUnsafe())
890
+ }()
891
+ return bridge.create_Result_std__function_void____(__resultCpp)
892
+ } catch (let __error) {
893
+ let __exceptionPtr = __error.toCpp()
894
+ return bridge.create_Result_std__function_void____(__exceptionPtr)
895
+ }
896
+ }
897
+
872
898
  @inline(__always)
873
899
  public final func onProgress(callback: bridge.Func_void_PlayerProgress) -> bridge.Result_std__function_void____ {
874
900
  do {
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// QueueChangeReason.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /**
9
+ * Represents the JS union `QueueChangeReason`, backed by a C++ enum.
10
+ */
11
+ public typealias QueueChangeReason = margelo.nitro.queueplayer.QueueChangeReason
12
+
13
+ public extension QueueChangeReason {
14
+ /**
15
+ * Get a QueueChangeReason for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "set-queue":
21
+ self = .setQueue
22
+ case "add":
23
+ self = .add
24
+ case "remove":
25
+ self = .remove
26
+ case "move":
27
+ self = .move
28
+ case "clear":
29
+ self = .clear
30
+ case "shuffle":
31
+ self = .shuffle
32
+ default:
33
+ return nil
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Get the String value this QueueChangeReason represents.
39
+ */
40
+ var stringValue: String {
41
+ switch self {
42
+ case .setQueue:
43
+ return "set-queue"
44
+ case .add:
45
+ return "add"
46
+ case .remove:
47
+ return "remove"
48
+ case .move:
49
+ return "move"
50
+ case .clear:
51
+ return "clear"
52
+ case .shuffle:
53
+ return "shuffle"
54
+ }
55
+ }
56
+ }
@@ -57,6 +57,7 @@ namespace margelo::nitro::queueplayer {
57
57
  prototype.registerHybridMethod("getSleepTimer", &HybridTrackPlayerSpec::getSleepTimer);
58
58
  prototype.registerHybridMethod("onStateChange", &HybridTrackPlayerSpec::onStateChange);
59
59
  prototype.registerHybridMethod("onTrackChange", &HybridTrackPlayerSpec::onTrackChange);
60
+ prototype.registerHybridMethod("onQueueChange", &HybridTrackPlayerSpec::onQueueChange);
60
61
  prototype.registerHybridMethod("onProgress", &HybridTrackPlayerSpec::onProgress);
61
62
  prototype.registerHybridMethod("onPlaybackMilestone", &HybridTrackPlayerSpec::onPlaybackMilestone);
62
63
  prototype.registerHybridMethod("onError", &HybridTrackPlayerSpec::onError);