feat(android): support chromecast

This commit is contained in:
2026-07-26 19:27:41 +02:00
parent 6423ed0bc5
commit 06efcbf1aa
32 changed files with 902 additions and 57 deletions
+2
View File
@@ -19,6 +19,7 @@
#include "JFunc_void_double.hpp"
#include "JFunc_void_bool.hpp"
#include "JFunc_void_PlayerStatus.hpp"
#include "JFunc_void_CastStatus.hpp"
#include "JFunc_void.hpp"
#include "JFunc_void_std__string_std__string.hpp"
#include "JFunc_void_std__string.hpp"
@@ -65,6 +66,7 @@ void registerAllNatives() {
margelo::nitro::omni::JFunc_void_double_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_bool_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_PlayerStatus_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_CastStatus_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_std__string_std__string_cxx::registerNatives();
margelo::nitro::omni::JFunc_void_std__string_cxx::registerNatives();
+58
View File
@@ -0,0 +1,58 @@
///
/// JCastOptions.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#include <fbjni/fbjni.h>
#include "CastOptions.hpp"
#include <optional>
#include <string>
namespace margelo::nitro::omni {
using namespace facebook;
/**
* The C++ JNI bridge between the C++ struct "CastOptions" and the Kotlin data class "CastOptions".
*/
struct JCastOptions final: public jni::JavaClass<JCastOptions> {
public:
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/CastOptions;";
public:
/**
* Convert this Java/Kotlin-based struct to the C++ struct CastOptions by copying all values to C++.
*/
[[maybe_unused]]
[[nodiscard]]
CastOptions toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldReceiverApplicationId = clazz->getField<jni::JString>("receiverApplicationId");
jni::local_ref<jni::JString> receiverApplicationId = this->getFieldValue(fieldReceiverApplicationId);
return CastOptions(
receiverApplicationId != nullptr ? std::make_optional(receiverApplicationId->toStdString()) : std::nullopt
);
}
public:
/**
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
*/
[[maybe_unused]]
static jni::local_ref<JCastOptions::javaobject> fromCpp(const CastOptions& value) {
using JSignature = JCastOptions(jni::alias_ref<jni::JString>);
static const auto clazz = javaClassStatic();
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
return create(
clazz,
value.receiverApplicationId.has_value() ? jni::make_jstring(value.receiverApplicationId.value()) : nullptr
);
}
};
} // namespace margelo::nitro::omni
+77
View File
@@ -0,0 +1,77 @@
///
/// JFunc_void_CastStatus.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#include <fbjni/fbjni.h>
#include <functional>
#include "CastStatus.hpp"
#include <functional>
#include <NitroModules/JNICallable.hpp>
#include "JCastStatus.hpp"
namespace margelo::nitro::omni {
using namespace facebook;
/**
* Represents the Java/Kotlin callback `(value: CastStatus) -> Unit`.
* This can be passed around between C++ and Java/Kotlin.
*/
struct JFunc_void_CastStatus: public jni::JavaClass<JFunc_void_CastStatus> {
public:
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_CastStatus;";
public:
/**
* Invokes the function this `JFunc_void_CastStatus` instance holds through JNI.
*/
void invoke(CastStatus value) const {
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JCastStatus> /* value */)>("invoke");
method(self(), JCastStatus::fromCpp(value));
}
};
/**
* An implementation of Func_void_CastStatus that is backed by a C++ implementation (using `std::function<...>`)
*/
class JFunc_void_CastStatus_cxx final: public jni::HybridClass<JFunc_void_CastStatus_cxx, JFunc_void_CastStatus> {
public:
static jni::local_ref<JFunc_void_CastStatus::javaobject> fromCpp(const std::function<void(CastStatus /* value */)>& func) {
return JFunc_void_CastStatus_cxx::newObjectCxxArgs(func);
}
public:
/**
* Invokes the C++ `std::function<...>` this `JFunc_void_CastStatus_cxx` instance holds.
*/
void invoke_cxx(jni::alias_ref<JCastStatus> value) {
_func(value->toCpp());
}
public:
[[nodiscard]]
inline const std::function<void(CastStatus /* value */)>& getFunction() const {
return _func;
}
public:
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_CastStatus_cxx;";
static void registerNatives() {
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_CastStatus_cxx::invoke_cxx)});
}
private:
explicit JFunc_void_CastStatus_cxx(const std::function<void(CastStatus /* value */)>& func): _func(func) { }
private:
friend HybridBase;
std::function<void(CastStatus /* value */)> _func;
};
} // namespace margelo::nitro::omni
@@ -13,6 +13,8 @@ namespace margelo::nitro::omni { enum class NumberProperty; }
namespace margelo::nitro::omni { enum class BoolProperty; }
// Forward declaration of `PlayerStatus` to properly resolve imports.
namespace margelo::nitro::omni { enum class PlayerStatus; }
// Forward declaration of `CastStatus` to properly resolve imports.
namespace margelo::nitro::omni { enum class CastStatus; }
// Forward declaration of `Track` to properly resolve imports.
namespace margelo::nitro::omni { struct Track; }
// Forward declaration of `Rendition` to properly resolve imports.
@@ -29,6 +31,9 @@ namespace margelo::nitro::omni { struct Rendition; }
#include "PlayerStatus.hpp"
#include "JFunc_void_PlayerStatus.hpp"
#include "JPlayerStatus.hpp"
#include "CastStatus.hpp"
#include "JFunc_void_CastStatus.hpp"
#include "JCastStatus.hpp"
#include "JFunc_void.hpp"
#include <string>
#include "JFunc_void_std__string_std__string.hpp"
@@ -99,6 +104,14 @@ namespace margelo::nitro::omni {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_PlayerStatus::javaobject> /* cb */)>("removePlayerStatusListener_cxx");
method(_javaPart, JFunc_void_PlayerStatus_cxx::fromCpp(cb));
}
void JHybridOmniEventMapSpec::addCastStatusListener(const std::function<void(CastStatus /* value */)>& cb) {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_CastStatus::javaobject> /* cb */)>("addCastStatusListener_cxx");
method(_javaPart, JFunc_void_CastStatus_cxx::fromCpp(cb));
}
void JHybridOmniEventMapSpec::removeCastStatusListener(const std::function<void(CastStatus /* value */)>& cb) {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_CastStatus::javaobject> /* cb */)>("removeCastStatusListener_cxx");
method(_javaPart, JFunc_void_CastStatus_cxx::fromCpp(cb));
}
void JHybridOmniEventMapSpec::addOnEndListener(const std::function<void()>& cb) {
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void::javaobject> /* cb */)>("addOnEndListener_cxx");
method(_javaPart, JFunc_void_cxx::fromCpp(cb));
@@ -60,6 +60,8 @@ namespace margelo::nitro::omni {
void removeStateBoolListener(BoolProperty key, const std::function<void(bool /* value */)>& cb) override;
void addPlayerStatusListener(const std::function<void(PlayerStatus /* value */)>& cb) override;
void removePlayerStatusListener(const std::function<void(PlayerStatus /* value */)>& cb) override;
void addCastStatusListener(const std::function<void(CastStatus /* value */)>& cb) override;
void removeCastStatusListener(const std::function<void(CastStatus /* value */)>& cb) override;
void addOnEndListener(const std::function<void()>& cb) override;
void removeOnEndListener(const std::function<void()>& cb) override;
void addOnPrevListener(const std::function<void()>& cb) override;
@@ -23,6 +23,8 @@ namespace margelo::nitro::omni { enum class MixAudioMode; }
namespace margelo::nitro::omni { struct PlayerBackend; }
// Forward declaration of `AndroidBackend` to properly resolve imports.
namespace margelo::nitro::omni { enum class AndroidBackend; }
// Forward declaration of `CastOptions` to properly resolve imports.
namespace margelo::nitro::omni { struct CastOptions; }
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
@@ -45,6 +47,8 @@ namespace margelo::nitro::omni { enum class AndroidBackend; }
#include "JPlayerBackend.hpp"
#include "AndroidBackend.hpp"
#include "JAndroidBackend.hpp"
#include "CastOptions.hpp"
#include "JCastOptions.hpp"
namespace margelo::nitro::omni {
@@ -79,9 +83,9 @@ namespace margelo::nitro::omni {
// Methods
std::shared_ptr<HybridOmniPlayerSpec> JHybridOmniPlayerFactorySpec::createPlayer(const std::optional<Source>& props, const std::optional<PlayerBackend>& backend) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridOmniPlayerSpec::JavaPart>(jni::alias_ref<JSource> /* props */, jni::alias_ref<JPlayerBackend> /* backend */)>("createPlayer");
auto __result = method(_javaPart, props.has_value() ? JSource::fromCpp(props.value()) : nullptr, backend.has_value() ? JPlayerBackend::fromCpp(backend.value()) : nullptr);
std::shared_ptr<HybridOmniPlayerSpec> JHybridOmniPlayerFactorySpec::createPlayer(const std::optional<Source>& props, const std::optional<PlayerBackend>& backend, const std::optional<CastOptions>& cast) {
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JHybridOmniPlayerSpec::JavaPart>(jni::alias_ref<JSource> /* props */, jni::alias_ref<JPlayerBackend> /* backend */, jni::alias_ref<JCastOptions> /* cast */)>("createPlayer");
auto __result = method(_javaPart, props.has_value() ? JSource::fromCpp(props.value()) : nullptr, backend.has_value() ? JPlayerBackend::fromCpp(backend.value()) : nullptr, cast.has_value() ? JCastOptions::fromCpp(cast.value()) : nullptr);
return __result->getJHybridOmniPlayerSpec();
}
@@ -54,7 +54,7 @@ namespace margelo::nitro::omni {
public:
// Methods
std::shared_ptr<HybridOmniPlayerSpec> createPlayer(const std::optional<Source>& props, const std::optional<PlayerBackend>& backend) override;
std::shared_ptr<HybridOmniPlayerSpec> createPlayer(const std::optional<Source>& props, const std::optional<PlayerBackend>& backend, const std::optional<CastOptions>& cast) override;
private:
jni::global_ref<JHybridOmniPlayerFactorySpec::JavaPart> _javaPart;
@@ -0,0 +1,51 @@
///
/// CastOptions.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
package com.margelo.nitro.omni
import androidx.annotation.Keep
import com.facebook.proguard.annotations.DoNotStrip
import java.util.Objects
/**
* Represents the JavaScript object/struct "CastOptions".
*/
@DoNotStrip
@Keep
data class CastOptions(
@DoNotStrip
@Keep
val receiverApplicationId: String?
) {
/* primary constructor */
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is CastOptions) return false
return Objects.deepEquals(this.receiverApplicationId, other.receiverApplicationId)
}
override fun hashCode(): Int {
return arrayOf<Any?>(
receiverApplicationId
).contentDeepHashCode()
}
companion object {
/**
* Constructor called from C++
*/
@DoNotStrip
@Keep
@Suppress("unused")
@JvmStatic
private fun fromCpp(receiverApplicationId: String?): CastOptions {
return CastOptions(receiverApplicationId)
}
}
}
@@ -0,0 +1,80 @@
///
/// Func_void_CastStatus.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
package com.margelo.nitro.omni
import androidx.annotation.Keep
import com.facebook.jni.HybridData
import com.facebook.proguard.annotations.DoNotStrip
import dalvik.annotation.optimization.FastNative
/**
* Represents the JavaScript callback `(value: enum) => void`.
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
* or in Kotlin/Java (in which case it is a native callback).
*/
@DoNotStrip
@Keep
@Suppress("ClassName", "RedundantUnitReturnType")
fun interface Func_void_CastStatus: (CastStatus) -> Unit {
/**
* Call the given JS callback.
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
*/
@DoNotStrip
@Keep
override fun invoke(value: CastStatus): Unit
}
/**
* Represents the JavaScript callback `(value: enum) => void`.
* This is implemented in C++, via a `std::function<...>`.
* The callback might be coming from JS.
*/
@DoNotStrip
@Keep
@Suppress(
"KotlinJniMissingFunction", "unused",
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
)
class Func_void_CastStatus_cxx: Func_void_CastStatus {
@DoNotStrip
@Keep
private val mHybridData: HybridData
@DoNotStrip
@Keep
private constructor(hybridData: HybridData) {
mHybridData = hybridData
}
@DoNotStrip
@Keep
override fun invoke(value: CastStatus): Unit
= invoke_cxx(value)
@FastNative
private external fun invoke_cxx(value: CastStatus): Unit
}
/**
* Represents the JavaScript callback `(value: enum) => void`.
* This is implemented in Java/Kotlin, via a `(CastStatus) -> Unit`.
* The callback is always coming from native.
*/
@DoNotStrip
@Keep
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
class Func_void_CastStatus_java(private val function: (CastStatus) -> Unit): Func_void_CastStatus {
@DoNotStrip
@Keep
override fun invoke(value: CastStatus): Unit {
return this.function(value)
}
}
@@ -82,6 +82,24 @@ abstract class HybridOmniEventMapSpec: HybridObject() {
return __result
}
abstract fun addCastStatusListener(cb: (value: CastStatus) -> Unit): Unit
@DoNotStrip
@Keep
private fun addCastStatusListener_cxx(cb: Func_void_CastStatus): Unit {
val __result = addCastStatusListener(cb)
return __result
}
abstract fun removeCastStatusListener(cb: (value: CastStatus) -> Unit): Unit
@DoNotStrip
@Keep
private fun removeCastStatusListener_cxx(cb: Func_void_CastStatus): Unit {
val __result = removeCastStatusListener(cb)
return __result
}
abstract fun addOnEndListener(cb: () -> Unit): Unit
@DoNotStrip
@@ -30,7 +30,7 @@ abstract class HybridOmniPlayerFactorySpec: HybridObject() {
// Methods
@DoNotStrip
@Keep
abstract fun createPlayer(props: Source?, backend: PlayerBackend?): HybridOmniPlayerSpec
abstract fun createPlayer(props: Source?, backend: PlayerBackend?, cast: CastOptions?): HybridOmniPlayerSpec
// Default implementation of `HybridObject.toString()`
override fun toString(): String {