react-native-nitro-player 1.6.0-alpha.1 → 1.6.0
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.
- package/android/src/main/java/com/margelo/nitro/nitroplayer/HybridTrackPlayer.kt +6 -0
- package/android/src/main/java/com/margelo/nitro/nitroplayer/core/TrackPlayerCore.kt +59 -0
- package/android/src/main/java/com/margelo/nitro/nitroplayer/media/PlaybackService.kt +15 -0
- package/ios/HybridTrackPlayer.swift +4 -0
- package/lib/specs/TrackPlayer.nitro.d.ts +5 -0
- package/nitrogen/generated/android/NitroPlayerOnLoad.cpp +2 -0
- package/nitrogen/generated/android/c++/JFunc_void_TrackItem.hpp +85 -0
- package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.cpp +5 -0
- package/nitrogen/generated/android/c++/JHybridTrackPlayerSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/Func_void_TrackItem.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/HybridTrackPlayerSpec.kt +9 -0
- package/nitrogen/generated/ios/NitroPlayer-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NitroPlayer-Swift-Cxx-Bridge.hpp +22 -0
- package/nitrogen/generated/ios/c++/HybridTrackPlayerSpecSwift.hpp +6 -0
- package/nitrogen/generated/ios/swift/Func_void_TrackItem.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridTrackPlayerSpec_cxx.swift +16 -0
- package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridTrackPlayerSpec.hpp +1 -0
- package/package.json +1 -1
- package/src/specs/TrackPlayer.nitro.ts +5 -0
|
@@ -178,6 +178,11 @@ class HybridTrackPlayer : HybridTrackPlayerSpec() {
|
|
|
178
178
|
listenerIds += "onAndroidAutoConnectionChange" to id
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
override fun appStartedWithNotification(callback: (track: TrackItem) -> Unit) {
|
|
182
|
+
val id = core.addOnNotificationLaunchListener(callback)
|
|
183
|
+
listenerIds += "appStartedWithNotification" to id
|
|
184
|
+
}
|
|
185
|
+
|
|
181
186
|
override fun onTracksNeedUpdate(callback: (tracks: Array<TrackItem>, lookahead: Double) -> Unit) {
|
|
182
187
|
val id =
|
|
183
188
|
core.addOnTracksNeedUpdateListener { tracks, lookahead ->
|
|
@@ -213,6 +218,7 @@ class HybridTrackPlayer : HybridTrackPlayerSpec() {
|
|
|
213
218
|
"onTracksNeedUpdate" -> core.removeOnTracksNeedUpdateListener(id)
|
|
214
219
|
"onTemporaryQueueChange" -> core.removeOnTemporaryQueueChangeListener(id)
|
|
215
220
|
"onTimedMetadata" -> core.removeOnTimedMetadataListener(id)
|
|
221
|
+
"appStartedWithNotification" -> core.removeOnNotificationLaunchListener(id)
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
listenerIds.clear()
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
package com.margelo.nitro.nitroplayer.core
|
|
4
4
|
|
|
5
|
+
import android.app.Activity
|
|
6
|
+
import android.app.Application
|
|
5
7
|
import android.content.ComponentName
|
|
6
8
|
import android.content.Context
|
|
7
9
|
import android.content.Intent
|
|
8
10
|
import android.content.ServiceConnection
|
|
11
|
+
import android.os.Bundle
|
|
9
12
|
import android.os.Handler
|
|
10
13
|
import android.os.IBinder
|
|
11
14
|
import android.os.Looper
|
|
15
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
12
16
|
import com.margelo.nitro.nitroplayer.Reason
|
|
13
17
|
import com.margelo.nitro.nitroplayer.RepeatMode
|
|
14
18
|
import com.margelo.nitro.nitroplayer.TimedMetadata
|
|
@@ -95,6 +99,8 @@ class TrackPlayerCore private constructor(
|
|
|
95
99
|
ListenerRegistry<(TimedMetadata) -> Unit>()
|
|
96
100
|
internal val onCastStateChangeListeners =
|
|
97
101
|
ListenerRegistry<(com.margelo.nitro.nitroplayer.CastState, String?) -> Unit>()
|
|
102
|
+
internal val onNotificationLaunchListeners =
|
|
103
|
+
ListenerRegistry<(TrackItem) -> Unit>()
|
|
98
104
|
|
|
99
105
|
// ── Google Cast ──────────────────────────────────────────────────────────
|
|
100
106
|
|
|
@@ -390,4 +396,57 @@ class TrackPlayerCore private constructor(
|
|
|
390
396
|
fun addOnCastStateChangeListener(cb: (com.margelo.nitro.nitroplayer.CastState, String?) -> Unit): Long = onCastStateChangeListeners.add(cb)
|
|
391
397
|
|
|
392
398
|
fun removeOnCastStateChangeListener(id: Long): Boolean = onCastStateChangeListeners.remove(id)
|
|
399
|
+
|
|
400
|
+
// ── Notification-launch detection ─────────────────────────────────────
|
|
401
|
+
|
|
402
|
+
private var notificationLaunchDetectionRegistered = false
|
|
403
|
+
|
|
404
|
+
fun addOnNotificationLaunchListener(cb: (TrackItem) -> Unit): Long {
|
|
405
|
+
val id = onNotificationLaunchListeners.add(cb)
|
|
406
|
+
handler.post {
|
|
407
|
+
registerNotificationLaunchDetection()
|
|
408
|
+
checkNotificationLaunch((context as? ReactApplicationContext)?.currentActivity)
|
|
409
|
+
}
|
|
410
|
+
return id
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
fun removeOnNotificationLaunchListener(id: Long): Boolean = onNotificationLaunchListeners.remove(id)
|
|
414
|
+
|
|
415
|
+
private fun registerNotificationLaunchDetection() {
|
|
416
|
+
if (notificationLaunchDetectionRegistered) return
|
|
417
|
+
notificationLaunchDetectionRegistered = true
|
|
418
|
+
val app = context.applicationContext as? Application ?: return
|
|
419
|
+
app.registerActivityLifecycleCallbacks(
|
|
420
|
+
object : Application.ActivityLifecycleCallbacks {
|
|
421
|
+
override fun onActivityResumed(activity: Activity) = checkNotificationLaunch(activity)
|
|
422
|
+
|
|
423
|
+
override fun onActivityCreated(
|
|
424
|
+
activity: Activity,
|
|
425
|
+
savedInstanceState: Bundle?,
|
|
426
|
+
) {}
|
|
427
|
+
|
|
428
|
+
override fun onActivityStarted(activity: Activity) {}
|
|
429
|
+
|
|
430
|
+
override fun onActivityPaused(activity: Activity) {}
|
|
431
|
+
|
|
432
|
+
override fun onActivityStopped(activity: Activity) {}
|
|
433
|
+
|
|
434
|
+
override fun onActivitySaveInstanceState(
|
|
435
|
+
activity: Activity,
|
|
436
|
+
outState: Bundle,
|
|
437
|
+
) {}
|
|
438
|
+
|
|
439
|
+
override fun onActivityDestroyed(activity: Activity) {}
|
|
440
|
+
},
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Must run on the main looper — reads the player and mutates the activity intent
|
|
445
|
+
internal fun checkNotificationLaunch(activity: Activity?) {
|
|
446
|
+
val intent = activity?.intent ?: return
|
|
447
|
+
if (!intent.getBooleanExtra(NitroPlayerPlaybackService.EXTRA_STARTED_FROM_NOTIFICATION, false)) return
|
|
448
|
+
val track = getCurrentTrack() ?: return
|
|
449
|
+
intent.removeExtra(NitroPlayerPlaybackService.EXTRA_STARTED_FROM_NOTIFICATION)
|
|
450
|
+
onNotificationLaunchListeners.forEach { it(track) }
|
|
451
|
+
}
|
|
393
452
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.margelo.nitro.nitroplayer.media
|
|
2
2
|
|
|
3
|
+
import android.app.PendingIntent
|
|
3
4
|
import android.content.Intent
|
|
4
5
|
import android.os.Binder
|
|
5
6
|
import android.os.Handler
|
|
@@ -32,6 +33,7 @@ class NitroPlayerPlaybackService : MediaSessionService() {
|
|
|
32
33
|
|
|
33
34
|
companion object {
|
|
34
35
|
const val ACTION_LOCAL_BIND = "com.margelo.nitro.nitroplayer.LOCAL_BIND"
|
|
36
|
+
const val EXTRA_STARTED_FROM_NOTIFICATION = "com.margelo.nitro.nitroplayer.STARTED_FROM_NOTIFICATION"
|
|
35
37
|
|
|
36
38
|
@Volatile
|
|
37
39
|
var notificationSmallIconResName: String? = null
|
|
@@ -84,6 +86,7 @@ class NitroPlayerPlaybackService : MediaSessionService() {
|
|
|
84
86
|
mediaSession = MediaSession
|
|
85
87
|
.Builder(this, player)
|
|
86
88
|
.setCallback(MediaSessionCallbackFactory.create(this, playlistManager))
|
|
89
|
+
.apply { buildSessionActivity()?.let { setSessionActivity(it) } }
|
|
87
90
|
.build()
|
|
88
91
|
|
|
89
92
|
val provider = DefaultMediaNotificationProvider.Builder(this).build()
|
|
@@ -119,6 +122,18 @@ class NitroPlayerPlaybackService : MediaSessionService() {
|
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
|
|
125
|
+
// Content intent for the notification tap — newer Android has no fallback without it
|
|
126
|
+
private fun buildSessionActivity(): PendingIntent? {
|
|
127
|
+
val launch = packageManager.getLaunchIntentForPackage(packageName) ?: return null
|
|
128
|
+
launch.putExtra(EXTRA_STARTED_FROM_NOTIFICATION, true)
|
|
129
|
+
return PendingIntent.getActivity(
|
|
130
|
+
this,
|
|
131
|
+
0,
|
|
132
|
+
launch,
|
|
133
|
+
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
122
137
|
private fun applyNotificationSmallIcon() {
|
|
123
138
|
val name = notificationSmallIconResName ?: return
|
|
124
139
|
val provider = notificationProvider ?: return
|
|
@@ -188,6 +188,10 @@ final class HybridTrackPlayer: HybridTrackPlayerSpec {
|
|
|
188
188
|
// No-op on iOS
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
func appStartedWithNotification(callback: @escaping (_ track: TrackItem) -> Void) throws {
|
|
192
|
+
// No-op on iOS — Now Playing controls never launch the app
|
|
193
|
+
}
|
|
194
|
+
|
|
191
195
|
func isAndroidAutoConnected() throws -> Bool { false }
|
|
192
196
|
|
|
193
197
|
// MARK: - Event listeners (v2 — store IDs for cleanup)
|
|
@@ -46,6 +46,11 @@ export interface TrackPlayer extends HybridObject<{
|
|
|
46
46
|
* updates and ID3 frames emitted while a live stream plays.
|
|
47
47
|
*/
|
|
48
48
|
onTimedMetadata(callback: (metadata: TimedMetadata) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Fires when the app was opened by tapping the playback notification,
|
|
51
|
+
* with the track that was playing at tap time. Android only — no-op on iOS.
|
|
52
|
+
*/
|
|
53
|
+
appStartedWithNotification(callback: (track: TrackItem) => void): void;
|
|
49
54
|
onAndroidAutoConnectionChange(callback: (connected: boolean) => void): void;
|
|
50
55
|
isAndroidAutoConnected(): boolean;
|
|
51
56
|
setVolume(volume: number): Promise<void>;
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
#include "JFunc_void_double_double.hpp"
|
|
37
37
|
#include "JFunc_void_double_double_std__optional_bool_.hpp"
|
|
38
38
|
#include "JFunc_void_TimedMetadata.hpp"
|
|
39
|
+
#include "JFunc_void_TrackItem.hpp"
|
|
39
40
|
#include "JFunc_void_std__vector_TrackItem__double.hpp"
|
|
40
41
|
#include "JFunc_void_std__vector_TrackItem__std__vector_TrackItem_.hpp"
|
|
41
42
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
@@ -131,6 +132,7 @@ void registerAllNatives() {
|
|
|
131
132
|
margelo::nitro::nitroplayer::JFunc_void_double_double_cxx::registerNatives();
|
|
132
133
|
margelo::nitro::nitroplayer::JFunc_void_double_double_std__optional_bool__cxx::registerNatives();
|
|
133
134
|
margelo::nitro::nitroplayer::JFunc_void_TimedMetadata_cxx::registerNatives();
|
|
135
|
+
margelo::nitro::nitroplayer::JFunc_void_TrackItem_cxx::registerNatives();
|
|
134
136
|
margelo::nitro::nitroplayer::JFunc_void_std__vector_TrackItem__double_cxx::registerNatives();
|
|
135
137
|
margelo::nitro::nitroplayer::JFunc_void_std__vector_TrackItem__std__vector_TrackItem__cxx::registerNatives();
|
|
136
138
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_TrackItem.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 <functional>
|
|
15
|
+
#include <NitroModules/JNICallable.hpp>
|
|
16
|
+
#include "JTrackItem.hpp"
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <NitroModules/Null.hpp>
|
|
19
|
+
#include <variant>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include "JVariant_NullType_String.hpp"
|
|
22
|
+
#include <NitroModules/JNull.hpp>
|
|
23
|
+
#include <NitroModules/AnyMap.hpp>
|
|
24
|
+
#include <NitroModules/JAnyMap.hpp>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::nitroplayer {
|
|
27
|
+
|
|
28
|
+
using namespace facebook;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Represents the Java/Kotlin callback `(track: TrackItem) -> Unit`.
|
|
32
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
33
|
+
*/
|
|
34
|
+
struct JFunc_void_TrackItem: public jni::JavaClass<JFunc_void_TrackItem> {
|
|
35
|
+
public:
|
|
36
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_TrackItem;";
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
/**
|
|
40
|
+
* Invokes the function this `JFunc_void_TrackItem` instance holds through JNI.
|
|
41
|
+
*/
|
|
42
|
+
void invoke(const TrackItem& track) const {
|
|
43
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JTrackItem> /* track */)>("invoke");
|
|
44
|
+
method(self(), JTrackItem::fromCpp(track));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An implementation of Func_void_TrackItem that is backed by a C++ implementation (using `std::function<...>`)
|
|
50
|
+
*/
|
|
51
|
+
class JFunc_void_TrackItem_cxx final: public jni::HybridClass<JFunc_void_TrackItem_cxx, JFunc_void_TrackItem> {
|
|
52
|
+
public:
|
|
53
|
+
static jni::local_ref<JFunc_void_TrackItem::javaobject> fromCpp(const std::function<void(const TrackItem& /* track */)>& func) {
|
|
54
|
+
return JFunc_void_TrackItem_cxx::newObjectCxxArgs(func);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
/**
|
|
59
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_TrackItem_cxx` instance holds.
|
|
60
|
+
*/
|
|
61
|
+
void invoke_cxx(jni::alias_ref<JTrackItem> track) {
|
|
62
|
+
_func(track->toCpp());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
[[nodiscard]]
|
|
67
|
+
inline const std::function<void(const TrackItem& /* track */)>& getFunction() const {
|
|
68
|
+
return _func;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public:
|
|
72
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitroplayer/Func_void_TrackItem_cxx;";
|
|
73
|
+
static void registerNatives() {
|
|
74
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_TrackItem_cxx::invoke_cxx)});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private:
|
|
78
|
+
explicit JFunc_void_TrackItem_cxx(const std::function<void(const TrackItem& /* track */)>& func): _func(func) { }
|
|
79
|
+
|
|
80
|
+
private:
|
|
81
|
+
friend HybridBase;
|
|
82
|
+
std::function<void(const TrackItem& /* track */)> _func;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro::nitroplayer
|
|
@@ -60,6 +60,7 @@ namespace margelo::nitro::nitroplayer { struct TimedMetadata; }
|
|
|
60
60
|
#include "TimedMetadata.hpp"
|
|
61
61
|
#include "JFunc_void_TimedMetadata.hpp"
|
|
62
62
|
#include "JTimedMetadata.hpp"
|
|
63
|
+
#include "JFunc_void_TrackItem.hpp"
|
|
63
64
|
#include "JFunc_void_bool.hpp"
|
|
64
65
|
#include "JFunc_void_std__vector_TrackItem__double.hpp"
|
|
65
66
|
#include "JFunc_void_std__vector_TrackItem__std__vector_TrackItem_.hpp"
|
|
@@ -329,6 +330,10 @@ namespace margelo::nitro::nitroplayer {
|
|
|
329
330
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_TimedMetadata::javaobject> /* callback */)>("onTimedMetadata_cxx");
|
|
330
331
|
method(_javaPart, JFunc_void_TimedMetadata_cxx::fromCpp(callback));
|
|
331
332
|
}
|
|
333
|
+
void JHybridTrackPlayerSpec::appStartedWithNotification(const std::function<void(const TrackItem& /* track */)>& callback) {
|
|
334
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_TrackItem::javaobject> /* callback */)>("appStartedWithNotification_cxx");
|
|
335
|
+
method(_javaPart, JFunc_void_TrackItem_cxx::fromCpp(callback));
|
|
336
|
+
}
|
|
332
337
|
void JHybridTrackPlayerSpec::onAndroidAutoConnectionChange(const std::function<void(bool /* connected */)>& callback) {
|
|
333
338
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_bool::javaobject> /* callback */)>("onAndroidAutoConnectionChange_cxx");
|
|
334
339
|
method(_javaPart, JFunc_void_bool_cxx::fromCpp(callback));
|
|
@@ -73,6 +73,7 @@ namespace margelo::nitro::nitroplayer {
|
|
|
73
73
|
void onSeek(const std::function<void(double /* position */, double /* totalDuration */)>& callback) override;
|
|
74
74
|
void onPlaybackProgressChange(const std::function<void(double /* position */, double /* totalDuration */, std::optional<bool> /* isManuallySeeked */)>& callback) override;
|
|
75
75
|
void onTimedMetadata(const std::function<void(const TimedMetadata& /* metadata */)>& callback) override;
|
|
76
|
+
void appStartedWithNotification(const std::function<void(const TrackItem& /* track */)>& callback) override;
|
|
76
77
|
void onAndroidAutoConnectionChange(const std::function<void(bool /* connected */)>& callback) override;
|
|
77
78
|
bool isAndroidAutoConnected() override;
|
|
78
79
|
std::shared_ptr<Promise<void>> setVolume(double volume) override;
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/Func_void_TrackItem.kt
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_TrackItem.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 `(track: struct) => 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_TrackItem: (TrackItem) -> 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(track: TrackItem): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(track: struct) => 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_TrackItem_cxx: Func_void_TrackItem {
|
|
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(track: TrackItem): Unit
|
|
60
|
+
= invoke_cxx(track)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(track: TrackItem): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(track: struct) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(TrackItem) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_TrackItem_java(private val function: (TrackItem) -> Unit): Func_void_TrackItem {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(track: TrackItem): Unit {
|
|
78
|
+
return this.function(track)
|
|
79
|
+
}
|
|
80
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroplayer/HybridTrackPlayerSpec.kt
CHANGED
|
@@ -130,6 +130,15 @@ abstract class HybridTrackPlayerSpec: HybridObject() {
|
|
|
130
130
|
return __result
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
abstract fun appStartedWithNotification(callback: (track: TrackItem) -> Unit): Unit
|
|
134
|
+
|
|
135
|
+
@DoNotStrip
|
|
136
|
+
@Keep
|
|
137
|
+
private fun appStartedWithNotification_cxx(callback: Func_void_TrackItem): Unit {
|
|
138
|
+
val __result = appStartedWithNotification(callback)
|
|
139
|
+
return __result
|
|
140
|
+
}
|
|
141
|
+
|
|
133
142
|
abstract fun onAndroidAutoConnectionChange(callback: (connected: Boolean) -> Unit): Unit
|
|
134
143
|
|
|
135
144
|
@DoNotStrip
|
|
@@ -323,6 +323,14 @@ namespace margelo::nitro::nitroplayer::bridge::swift {
|
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
// pragma MARK: std::function<void(const TrackItem& /* track */)>
|
|
327
|
+
Func_void_TrackItem create_Func_void_TrackItem(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
328
|
+
auto swiftClosure = NitroPlayer::Func_void_TrackItem::fromUnsafe(swiftClosureWrapper);
|
|
329
|
+
return [swiftClosure = std::move(swiftClosure)](const TrackItem& track) mutable -> void {
|
|
330
|
+
swiftClosure.call(track);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
326
334
|
// pragma MARK: std::function<void(const std::vector<TrackItem>& /* tracks */, double /* lookahead */)>
|
|
327
335
|
Func_void_std__vector_TrackItem__double create_Func_void_std__vector_TrackItem__double(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
328
336
|
auto swiftClosure = NitroPlayer::Func_void_std__vector_TrackItem__double::fromUnsafe(swiftClosureWrapper);
|
|
@@ -1752,6 +1752,28 @@ namespace margelo::nitro::nitroplayer::bridge::swift {
|
|
|
1752
1752
|
return Func_void_TimedMetadata_Wrapper(std::move(value));
|
|
1753
1753
|
}
|
|
1754
1754
|
|
|
1755
|
+
// pragma MARK: std::function<void(const TrackItem& /* track */)>
|
|
1756
|
+
/**
|
|
1757
|
+
* Specialized version of `std::function<void(const TrackItem&)>`.
|
|
1758
|
+
*/
|
|
1759
|
+
using Func_void_TrackItem = std::function<void(const TrackItem& /* track */)>;
|
|
1760
|
+
/**
|
|
1761
|
+
* Wrapper class for a `std::function<void(const TrackItem& / * track * /)>`, this can be used from Swift.
|
|
1762
|
+
*/
|
|
1763
|
+
class Func_void_TrackItem_Wrapper final {
|
|
1764
|
+
public:
|
|
1765
|
+
explicit Func_void_TrackItem_Wrapper(std::function<void(const TrackItem& /* track */)>&& func): _function(std::make_unique<std::function<void(const TrackItem& /* track */)>>(std::move(func))) {}
|
|
1766
|
+
inline void call(TrackItem track) const noexcept {
|
|
1767
|
+
_function->operator()(track);
|
|
1768
|
+
}
|
|
1769
|
+
private:
|
|
1770
|
+
std::unique_ptr<std::function<void(const TrackItem& /* track */)>> _function;
|
|
1771
|
+
} SWIFT_NONCOPYABLE;
|
|
1772
|
+
Func_void_TrackItem create_Func_void_TrackItem(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
1773
|
+
inline Func_void_TrackItem_Wrapper wrap_Func_void_TrackItem(Func_void_TrackItem value) noexcept {
|
|
1774
|
+
return Func_void_TrackItem_Wrapper(std::move(value));
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1755
1777
|
// pragma MARK: std::function<void(const std::vector<TrackItem>& /* tracks */, double /* lookahead */)>
|
|
1756
1778
|
/**
|
|
1757
1779
|
* Specialized version of `std::function<void(const std::vector<TrackItem>&, double)>`.
|
|
@@ -238,6 +238,12 @@ namespace margelo::nitro::nitroplayer {
|
|
|
238
238
|
std::rethrow_exception(__result.error());
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
+
inline void appStartedWithNotification(const std::function<void(const TrackItem& /* track */)>& callback) override {
|
|
242
|
+
auto __result = _swiftPart.appStartedWithNotification(callback);
|
|
243
|
+
if (__result.hasError()) [[unlikely]] {
|
|
244
|
+
std::rethrow_exception(__result.error());
|
|
245
|
+
}
|
|
246
|
+
}
|
|
241
247
|
inline void onAndroidAutoConnectionChange(const std::function<void(bool /* connected */)>& callback) override {
|
|
242
248
|
auto __result = _swiftPart.onAndroidAutoConnectionChange(callback);
|
|
243
249
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_TrackItem.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 `(_ track: TrackItem) -> 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_TrackItem {
|
|
15
|
+
public typealias bridge = margelo.nitro.nitroplayer.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ track: TrackItem) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ track: TrackItem) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(track: TrackItem) -> Void {
|
|
25
|
+
self.closure(track)
|
|
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_TrackItem`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_TrackItem>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_TrackItem {
|
|
44
|
+
return Unmanaged<Func_void_TrackItem>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -32,6 +32,7 @@ public protocol HybridTrackPlayerSpec_protocol: HybridObject {
|
|
|
32
32
|
func onSeek(callback: @escaping (_ position: Double, _ totalDuration: Double) -> Void) throws -> Void
|
|
33
33
|
func onPlaybackProgressChange(callback: @escaping (_ position: Double, _ totalDuration: Double, _ isManuallySeeked: Bool?) -> Void) throws -> Void
|
|
34
34
|
func onTimedMetadata(callback: @escaping (_ metadata: TimedMetadata) -> Void) throws -> Void
|
|
35
|
+
func appStartedWithNotification(callback: @escaping (_ track: TrackItem) -> Void) throws -> Void
|
|
35
36
|
func onAndroidAutoConnectionChange(callback: @escaping (_ connected: Bool) -> Void) throws -> Void
|
|
36
37
|
func isAndroidAutoConnected() throws -> Bool
|
|
37
38
|
func setVolume(volume: Double) throws -> Promise<Void>
|
|
@@ -494,6 +494,22 @@ open class HybridTrackPlayerSpec_cxx {
|
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
@inline(__always)
|
|
498
|
+
public final func appStartedWithNotification(callback: bridge.Func_void_TrackItem) -> bridge.Result_void_ {
|
|
499
|
+
do {
|
|
500
|
+
try self.__implementation.appStartedWithNotification(callback: { () -> (TrackItem) -> Void in
|
|
501
|
+
let __wrappedFunction = bridge.wrap_Func_void_TrackItem(callback)
|
|
502
|
+
return { (__track: TrackItem) -> Void in
|
|
503
|
+
__wrappedFunction.call(__track)
|
|
504
|
+
}
|
|
505
|
+
}())
|
|
506
|
+
return bridge.create_Result_void_()
|
|
507
|
+
} catch (let __error) {
|
|
508
|
+
let __exceptionPtr = __error.toCpp()
|
|
509
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
497
513
|
@inline(__always)
|
|
498
514
|
public final func onAndroidAutoConnectionChange(callback: bridge.Func_void_bool) -> bridge.Result_void_ {
|
|
499
515
|
do {
|
|
@@ -33,6 +33,7 @@ namespace margelo::nitro::nitroplayer {
|
|
|
33
33
|
prototype.registerHybridMethod("onSeek", &HybridTrackPlayerSpec::onSeek);
|
|
34
34
|
prototype.registerHybridMethod("onPlaybackProgressChange", &HybridTrackPlayerSpec::onPlaybackProgressChange);
|
|
35
35
|
prototype.registerHybridMethod("onTimedMetadata", &HybridTrackPlayerSpec::onTimedMetadata);
|
|
36
|
+
prototype.registerHybridMethod("appStartedWithNotification", &HybridTrackPlayerSpec::appStartedWithNotification);
|
|
36
37
|
prototype.registerHybridMethod("onAndroidAutoConnectionChange", &HybridTrackPlayerSpec::onAndroidAutoConnectionChange);
|
|
37
38
|
prototype.registerHybridMethod("isAndroidAutoConnected", &HybridTrackPlayerSpec::isAndroidAutoConnected);
|
|
38
39
|
prototype.registerHybridMethod("setVolume", &HybridTrackPlayerSpec::setVolume);
|
|
@@ -91,6 +91,7 @@ namespace margelo::nitro::nitroplayer {
|
|
|
91
91
|
virtual void onSeek(const std::function<void(double /* position */, double /* totalDuration */)>& callback) = 0;
|
|
92
92
|
virtual void onPlaybackProgressChange(const std::function<void(double /* position */, double /* totalDuration */, std::optional<bool> /* isManuallySeeked */)>& callback) = 0;
|
|
93
93
|
virtual void onTimedMetadata(const std::function<void(const TimedMetadata& /* metadata */)>& callback) = 0;
|
|
94
|
+
virtual void appStartedWithNotification(const std::function<void(const TrackItem& /* track */)>& callback) = 0;
|
|
94
95
|
virtual void onAndroidAutoConnectionChange(const std::function<void(bool /* connected */)>& callback) = 0;
|
|
95
96
|
virtual bool isAndroidAutoConnected() = 0;
|
|
96
97
|
virtual std::shared_ptr<Promise<void>> setVolume(double volume) = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-player",
|
|
3
|
-
"version": "1.6.0
|
|
3
|
+
"version": "1.6.0",
|
|
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",
|
|
@@ -102,6 +102,11 @@ export interface TrackPlayer extends HybridObject<{
|
|
|
102
102
|
* updates and ID3 frames emitted while a live stream plays.
|
|
103
103
|
*/
|
|
104
104
|
onTimedMetadata(callback: (metadata: TimedMetadata) => void): void
|
|
105
|
+
/**
|
|
106
|
+
* Fires when the app was opened by tapping the playback notification,
|
|
107
|
+
* with the track that was playing at tap time. Android only — no-op on iOS.
|
|
108
|
+
*/
|
|
109
|
+
appStartedWithNotification(callback: (track: TrackItem) => void): void
|
|
105
110
|
onAndroidAutoConnectionChange(callback: (connected: boolean) => void): void
|
|
106
111
|
isAndroidAutoConnected(): boolean
|
|
107
112
|
setVolume(volume: number): Promise<void>
|