react-native-nitro-player 1.7.0-alpha.4 → 1.7.0-alpha.5

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 (48) hide show
  1. package/android/src/main/AndroidManifest.xml +8 -0
  2. package/android/src/main/java/com/margelo/nitro/nitroplayer/HybridAndroidAutoMediaLibrary.kt +51 -0
  3. package/android/src/main/java/com/margelo/nitro/nitroplayer/connection/AndroidAutoConnectionDetector.kt +2 -2
  4. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/ExoPlayerCore.kt +17 -2
  5. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/NitroPlayerLogger.kt +2 -2
  6. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerAndroidAuto.kt +41 -31
  7. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerCast.kt +1 -1
  8. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerCore.kt +47 -2
  9. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerListener.kt +10 -17
  10. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerNotify.kt +5 -0
  11. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerPlayback.kt +3 -1
  12. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerQueueBuild.kt +16 -1
  13. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerRecovery.kt +97 -0
  14. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerSetup.kt +0 -5
  15. package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerUrlLoader.kt +15 -2
  16. package/android/src/main/java/com/margelo/nitro/nitroplayer/download/DownloadDatabase.kt +3 -0
  17. package/android/src/main/java/com/margelo/nitro/nitroplayer/download/TrackItemJson.kt +6 -0
  18. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/CastSessionController.kt +2 -0
  19. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaBrowserService.kt +96 -45
  20. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaLibrary.kt +2 -0
  21. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaLibraryManager.kt +147 -0
  22. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaLibraryParser.kt +3 -0
  23. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaSessionCallbackFactory.kt +102 -24
  24. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/MediaSessionManager.kt +44 -2
  25. package/android/src/main/java/com/margelo/nitro/nitroplayer/media/PlaybackService.kt +57 -1
  26. package/android/src/main/java/com/margelo/nitro/nitroplayer/playlist/PlaylistManager.kt +15 -0
  27. package/lib/index.js +5 -1
  28. package/lib/specs/AndroidAutoMediaLibrary.nitro.d.ts +12 -0
  29. package/lib/types/AndroidAutoMediaLibrary.d.ts +11 -0
  30. package/lib/utils/androidAutoMediaLibrary.d.ts +13 -1
  31. package/lib/utils/androidAutoMediaLibrary.js +23 -0
  32. package/nitrogen/generated/android/NitroPlayerOnLoad.cpp +6 -0
  33. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  34. package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
  35. package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp +76 -0
  36. package/nitrogen/generated/android/c++/JHybridAndroidAutoMediaLibrarySpec.cpp +29 -0
  37. package/nitrogen/generated/android/c++/JHybridAndroidAutoMediaLibrarySpec.hpp +6 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/Func_void.kt +80 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/Func_void_std__string.kt +80 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/Func_void_std__string_std__string.kt +80 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/HybridAndroidAutoMediaLibrarySpec.kt +44 -0
  42. package/nitrogen/generated/shared/c++/HybridAndroidAutoMediaLibrarySpec.cpp +6 -0
  43. package/nitrogen/generated/shared/c++/HybridAndroidAutoMediaLibrarySpec.hpp +7 -0
  44. package/package.json +1 -1
  45. package/src/index.ts +9 -1
  46. package/src/specs/AndroidAutoMediaLibrary.nitro.ts +18 -0
  47. package/src/types/AndroidAutoMediaLibrary.ts +24 -0
  48. package/src/utils/androidAutoMediaLibrary.ts +48 -1
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// JFunc_void_std__string.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 <string>
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+
17
+ namespace margelo::nitro::nitroplayer {
18
+
19
+ using namespace facebook;
20
+
21
+ /**
22
+ * Represents the Java/Kotlin callback `(action: String) -> Unit`.
23
+ * This can be passed around between C++ and Java/Kotlin.
24
+ */
25
+ struct JFunc_void_std__string: public jni::JavaClass<JFunc_void_std__string> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_std__string;";
28
+
29
+ public:
30
+ /**
31
+ * Invokes the function this `JFunc_void_std__string` instance holds through JNI.
32
+ */
33
+ void invoke(const std::string& action) const {
34
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* action */)>("invoke");
35
+ method(self(), jni::make_jstring(action));
36
+ }
37
+ };
38
+
39
+ /**
40
+ * An implementation of Func_void_std__string that is backed by a C++ implementation (using `std::function<...>`)
41
+ */
42
+ class JFunc_void_std__string_cxx final: public jni::HybridClass<JFunc_void_std__string_cxx, JFunc_void_std__string> {
43
+ public:
44
+ static jni::local_ref<JFunc_void_std__string::javaobject> fromCpp(const std::function<void(const std::string& /* action */)>& func) {
45
+ return JFunc_void_std__string_cxx::newObjectCxxArgs(func);
46
+ }
47
+
48
+ public:
49
+ /**
50
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_cxx` instance holds.
51
+ */
52
+ void invoke_cxx(jni::alias_ref<jni::JString> action) {
53
+ _func(action->toStdString());
54
+ }
55
+
56
+ public:
57
+ [[nodiscard]]
58
+ inline const std::function<void(const std::string& /* action */)>& getFunction() const {
59
+ return _func;
60
+ }
61
+
62
+ public:
63
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_std__string_cxx;";
64
+ static void registerNatives() {
65
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_cxx::invoke_cxx)});
66
+ }
67
+
68
+ private:
69
+ explicit JFunc_void_std__string_cxx(const std::function<void(const std::string& /* action */)>& func): _func(func) { }
70
+
71
+ private:
72
+ friend HybridBase;
73
+ std::function<void(const std::string& /* action */)> _func;
74
+ };
75
+
76
+ } // namespace margelo::nitro::nitroplayer
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// JFunc_void_std__string_std__string.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 <string>
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+
17
+ namespace margelo::nitro::nitroplayer {
18
+
19
+ using namespace facebook;
20
+
21
+ /**
22
+ * Represents the Java/Kotlin callback `(requestId: String, parentId: String) -> Unit`.
23
+ * This can be passed around between C++ and Java/Kotlin.
24
+ */
25
+ struct JFunc_void_std__string_std__string: public jni::JavaClass<JFunc_void_std__string_std__string> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_std__string_std__string;";
28
+
29
+ public:
30
+ /**
31
+ * Invokes the function this `JFunc_void_std__string_std__string` instance holds through JNI.
32
+ */
33
+ void invoke(const std::string& requestId, const std::string& parentId) const {
34
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* requestId */, jni::alias_ref<jni::JString> /* parentId */)>("invoke");
35
+ method(self(), jni::make_jstring(requestId), jni::make_jstring(parentId));
36
+ }
37
+ };
38
+
39
+ /**
40
+ * An implementation of Func_void_std__string_std__string that is backed by a C++ implementation (using `std::function<...>`)
41
+ */
42
+ class JFunc_void_std__string_std__string_cxx final: public jni::HybridClass<JFunc_void_std__string_std__string_cxx, JFunc_void_std__string_std__string> {
43
+ public:
44
+ static jni::local_ref<JFunc_void_std__string_std__string::javaobject> fromCpp(const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& func) {
45
+ return JFunc_void_std__string_std__string_cxx::newObjectCxxArgs(func);
46
+ }
47
+
48
+ public:
49
+ /**
50
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_std__string_cxx` instance holds.
51
+ */
52
+ void invoke_cxx(jni::alias_ref<jni::JString> requestId, jni::alias_ref<jni::JString> parentId) {
53
+ _func(requestId->toStdString(), parentId->toStdString());
54
+ }
55
+
56
+ public:
57
+ [[nodiscard]]
58
+ inline const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& getFunction() const {
59
+ return _func;
60
+ }
61
+
62
+ public:
63
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_std__string_std__string_cxx;";
64
+ static void registerNatives() {
65
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_std__string_cxx::invoke_cxx)});
66
+ }
67
+
68
+ private:
69
+ explicit JFunc_void_std__string_std__string_cxx(const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& func): _func(func) { }
70
+
71
+ private:
72
+ friend HybridBase;
73
+ std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)> _func;
74
+ };
75
+
76
+ } // namespace margelo::nitro::nitroplayer
@@ -13,6 +13,11 @@
13
13
  #include <NitroModules/JPromise.hpp>
14
14
  #include <NitroModules/JUnit.hpp>
15
15
  #include <string>
16
+ #include <functional>
17
+ #include "JFunc_void_std__string_std__string.hpp"
18
+ #include <NitroModules/JNICallable.hpp>
19
+ #include "JFunc_void_std__string.hpp"
20
+ #include "JFunc_void.hpp"
16
21
 
17
22
  namespace margelo::nitro::nitroplayer {
18
23
 
@@ -77,5 +82,29 @@ namespace margelo::nitro::nitroplayer {
77
82
  return __promise;
78
83
  }();
79
84
  }
85
+ void JHybridAndroidAutoMediaLibrarySpec::onLoadChildren(const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& callback) {
86
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__string_std__string::javaobject> /* callback */)>("onLoadChildren_cxx");
87
+ method(_javaPart, JFunc_void_std__string_std__string_cxx::fromCpp(callback));
88
+ }
89
+ void JHybridAndroidAutoMediaLibrarySpec::onSearch(const std::function<void(const std::string& /* requestId */, const std::string& /* query */)>& callback) {
90
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__string_std__string::javaobject> /* callback */)>("onSearch_cxx");
91
+ method(_javaPart, JFunc_void_std__string_std__string_cxx::fromCpp(callback));
92
+ }
93
+ void JHybridAndroidAutoMediaLibrarySpec::resolveRequest(const std::string& requestId, const std::string& itemsJson) {
94
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* requestId */, jni::alias_ref<jni::JString> /* itemsJson */)>("resolveRequest");
95
+ method(_javaPart, jni::make_jstring(requestId), jni::make_jstring(itemsJson));
96
+ }
97
+ void JHybridAndroidAutoMediaLibrarySpec::setSessionButtons(const std::string& buttonsJson) {
98
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* buttonsJson */)>("setSessionButtons");
99
+ method(_javaPart, jni::make_jstring(buttonsJson));
100
+ }
101
+ void JHybridAndroidAutoMediaLibrarySpec::onSessionButtonPress(const std::function<void(const std::string& /* action */)>& callback) {
102
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__string::javaobject> /* callback */)>("onSessionButtonPress_cxx");
103
+ method(_javaPart, JFunc_void_std__string_cxx::fromCpp(callback));
104
+ }
105
+ void JHybridAndroidAutoMediaLibrarySpec::onPlaybackResumption(const std::function<void()>& callback) {
106
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void::javaobject> /* callback */)>("onPlaybackResumption_cxx");
107
+ method(_javaPart, JFunc_void_cxx::fromCpp(callback));
108
+ }
80
109
 
81
110
  } // namespace margelo::nitro::nitroplayer
@@ -56,6 +56,12 @@ namespace margelo::nitro::nitroplayer {
56
56
  // Methods
57
57
  std::shared_ptr<Promise<void>> setMediaLibrary(const std::string& libraryJson) override;
58
58
  std::shared_ptr<Promise<void>> clearMediaLibrary() override;
59
+ void onLoadChildren(const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& callback) override;
60
+ void onSearch(const std::function<void(const std::string& /* requestId */, const std::string& /* query */)>& callback) override;
61
+ void resolveRequest(const std::string& requestId, const std::string& itemsJson) override;
62
+ void setSessionButtons(const std::string& buttonsJson) override;
63
+ void onSessionButtonPress(const std::function<void(const std::string& /* action */)>& callback) override;
64
+ void onPlaybackResumption(const std::function<void()>& callback) override;
59
65
 
60
66
  private:
61
67
  jni::global_ref<JHybridAndroidAutoMediaLibrarySpec::JavaPart> _javaPart;
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void.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.nitroplayer
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 `() => 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: () -> 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(): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `() => 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_cxx: Func_void {
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(): Unit
60
+ = invoke_cxx()
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `() => void`.
68
+ * This is implemented in Java/Kotlin, via a `() -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_java(private val function: () -> Unit): Func_void {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(): Unit {
78
+ return this.function()
79
+ }
80
+ }
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_std__string.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.nitroplayer
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 `(action: string) => 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__string: (String) -> 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(action: String): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(action: string) => 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__string_cxx: Func_void_std__string {
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(action: String): Unit
60
+ = invoke_cxx(action)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(action: String): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(action: string) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(String) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_std__string_java(private val function: (String) -> Unit): Func_void_std__string {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(action: String): Unit {
78
+ return this.function(action)
79
+ }
80
+ }
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_std__string_std__string.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.nitroplayer
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 `(requestId: string, parentId: string) => 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__string_std__string: (String, String) -> 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(requestId: String, parentId: String): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(requestId: string, parentId: string) => 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__string_std__string_cxx: Func_void_std__string_std__string {
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(requestId: String, parentId: String): Unit
60
+ = invoke_cxx(requestId,parentId)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(requestId: String, parentId: String): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(requestId: string, parentId: string) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(String, String) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_std__string_std__string_java(private val function: (String, String) -> Unit): Func_void_std__string_std__string {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(requestId: String, parentId: String): Unit {
78
+ return this.function(requestId, parentId)
79
+ }
80
+ }
@@ -36,6 +36,50 @@ abstract class HybridAndroidAutoMediaLibrarySpec: HybridObject() {
36
36
  @DoNotStrip
37
37
  @Keep
38
38
  abstract fun clearMediaLibrary(): Promise<Unit>
39
+
40
+ abstract fun onLoadChildren(callback: (requestId: String, parentId: String) -> Unit): Unit
41
+
42
+ @DoNotStrip
43
+ @Keep
44
+ private fun onLoadChildren_cxx(callback: Func_void_std__string_std__string): Unit {
45
+ val __result = onLoadChildren(callback)
46
+ return __result
47
+ }
48
+
49
+ abstract fun onSearch(callback: (requestId: String, query: String) -> Unit): Unit
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private fun onSearch_cxx(callback: Func_void_std__string_std__string): Unit {
54
+ val __result = onSearch(callback)
55
+ return __result
56
+ }
57
+
58
+ @DoNotStrip
59
+ @Keep
60
+ abstract fun resolveRequest(requestId: String, itemsJson: String): Unit
61
+
62
+ @DoNotStrip
63
+ @Keep
64
+ abstract fun setSessionButtons(buttonsJson: String): Unit
65
+
66
+ abstract fun onSessionButtonPress(callback: (action: String) -> Unit): Unit
67
+
68
+ @DoNotStrip
69
+ @Keep
70
+ private fun onSessionButtonPress_cxx(callback: Func_void_std__string): Unit {
71
+ val __result = onSessionButtonPress(callback)
72
+ return __result
73
+ }
74
+
75
+ abstract fun onPlaybackResumption(callback: () -> Unit): Unit
76
+
77
+ @DoNotStrip
78
+ @Keep
79
+ private fun onPlaybackResumption_cxx(callback: Func_void): Unit {
80
+ val __result = onPlaybackResumption(callback)
81
+ return __result
82
+ }
39
83
 
40
84
  // Default implementation of `HybridObject.toString()`
41
85
  override fun toString(): String {
@@ -16,6 +16,12 @@ namespace margelo::nitro::nitroplayer {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridMethod("setMediaLibrary", &HybridAndroidAutoMediaLibrarySpec::setMediaLibrary);
18
18
  prototype.registerHybridMethod("clearMediaLibrary", &HybridAndroidAutoMediaLibrarySpec::clearMediaLibrary);
19
+ prototype.registerHybridMethod("onLoadChildren", &HybridAndroidAutoMediaLibrarySpec::onLoadChildren);
20
+ prototype.registerHybridMethod("onSearch", &HybridAndroidAutoMediaLibrarySpec::onSearch);
21
+ prototype.registerHybridMethod("resolveRequest", &HybridAndroidAutoMediaLibrarySpec::resolveRequest);
22
+ prototype.registerHybridMethod("setSessionButtons", &HybridAndroidAutoMediaLibrarySpec::setSessionButtons);
23
+ prototype.registerHybridMethod("onSessionButtonPress", &HybridAndroidAutoMediaLibrarySpec::onSessionButtonPress);
24
+ prototype.registerHybridMethod("onPlaybackResumption", &HybridAndroidAutoMediaLibrarySpec::onPlaybackResumption);
19
25
  });
20
26
  }
21
27
 
@@ -17,6 +17,7 @@
17
17
 
18
18
  #include <NitroModules/Promise.hpp>
19
19
  #include <string>
20
+ #include <functional>
20
21
 
21
22
  namespace margelo::nitro::nitroplayer {
22
23
 
@@ -51,6 +52,12 @@ namespace margelo::nitro::nitroplayer {
51
52
  // Methods
52
53
  virtual std::shared_ptr<Promise<void>> setMediaLibrary(const std::string& libraryJson) = 0;
53
54
  virtual std::shared_ptr<Promise<void>> clearMediaLibrary() = 0;
55
+ virtual void onLoadChildren(const std::function<void(const std::string& /* requestId */, const std::string& /* parentId */)>& callback) = 0;
56
+ virtual void onSearch(const std::function<void(const std::string& /* requestId */, const std::string& /* query */)>& callback) = 0;
57
+ virtual void resolveRequest(const std::string& requestId, const std::string& itemsJson) = 0;
58
+ virtual void setSessionButtons(const std::string& buttonsJson) = 0;
59
+ virtual void onSessionButtonPress(const std::function<void(const std::string& /* action */)>& callback) = 0;
60
+ virtual void onPlaybackResumption(const std::function<void()>& callback) = 0;
54
61
 
55
62
  protected:
56
63
  // Hybrid Setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-player",
3
- "version": "1.7.0-alpha.4",
3
+ "version": "1.7.0-alpha.5",
4
4
  "description": "A powerful audio player library for React Native with playlist management, playback controls, and support for Android Auto and CarPlay",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // TODO: Export all HybridObjects here for the user
2
2
 
3
3
  import { NitroModules } from 'react-native-nitro-modules'
4
- import { Platform } from 'react-native'
4
+ import { AppRegistry, Platform } from 'react-native'
5
5
  import type {
6
6
  PlayerQueue as PlayerQueueType,
7
7
  TrackPlayer as TrackPlayerType,
@@ -13,6 +13,14 @@ import type { Cast as CastType } from './specs/Cast.nitro'
13
13
  import type { DownloadManager as DownloadManagerType } from './specs/DownloadManager.nitro'
14
14
  import type { Equalizer as EqualizerType } from './specs/Equalizer.nitro'
15
15
 
16
+ // Native runs this while it needs JS without a resumed activity (car, screen off): it keeps JS timers ticking
17
+ if (Platform.OS === 'android') {
18
+ AppRegistry.registerHeadlessTask(
19
+ 'NitroPlayerKeepAlive',
20
+ () => () => new Promise<void>(() => {})
21
+ )
22
+ }
23
+
16
24
  export const PlayerQueue =
17
25
  NitroModules.createHybridObject<PlayerQueueType>('PlayerQueue')
18
26
  export const TrackPlayer =
@@ -20,4 +20,22 @@ export interface AndroidAutoMediaLibrary extends HybridObject<{
20
20
  * Falls back to showing all playlists
21
21
  */
22
22
  clearMediaLibrary(): Promise<void>
23
+
24
+ /** Android Auto opened a folder published with `children: []`; answer with {@link resolveRequest}. */
25
+ onLoadChildren(callback: (requestId: string, parentId: string) => void): void
26
+
27
+ /** A car search, or a voice request the loaded playlists cannot match; answer with {@link resolveRequest}. */
28
+ onSearch(callback: (requestId: string, query: string) => void): void
29
+
30
+ /** Answers {@link onLoadChildren} / {@link onSearch} with a JSON array of MediaItem. */
31
+ resolveRequest(requestId: string, itemsJson: string): void
32
+
33
+ /** Replaces the session buttons with a JSON array of SessionButton. */
34
+ setSessionButtons(buttonsJson: string): void
35
+
36
+ /** Called with the button's `action` when a session button is pressed. */
37
+ onSessionButtonPress(callback: (action: string) => void): void
38
+
39
+ /** A controller asked to play with nothing loaded (car auto-play, play on connect); load the last queue now. */
40
+ onPlaybackResumption(callback: () => void): void
23
41
  }
@@ -38,6 +38,9 @@ export interface MediaItem {
38
38
 
39
39
  /** Layout type for folder items (overrides library default) */
40
40
  layoutType?: LayoutType
41
+
42
+ /** Group header; contiguous items sharing one are listed under it */
43
+ groupTitle?: string
41
44
  }
42
45
 
43
46
  /**
@@ -56,3 +59,24 @@ export interface MediaLibrary {
56
59
  /** Optional app icon URL */
57
60
  appIconUrl?: string
58
61
  }
62
+
63
+ export type SessionButtonIcon =
64
+ | 'heart'
65
+ | 'heart_filled'
66
+ | 'star'
67
+ | 'star_filled'
68
+ | 'thumb_up'
69
+ | 'thumb_up_filled'
70
+ | 'plus'
71
+ | 'check'
72
+
73
+ /** App-defined button beside the transport controls in Android Auto and the notification */
74
+ export interface SessionButton {
75
+ /** Passed to the press callback */
76
+ action: string
77
+
78
+ /** Accessibility label */
79
+ title: string
80
+
81
+ icon: SessionButtonIcon
82
+ }