diff --git a/android/src/main/java/dev/zoriya/omni/EventMap.kt b/android/src/main/java/dev/zoriya/omni/EventMap.kt new file mode 100644 index 0000000..22f6c03 --- /dev/null +++ b/android/src/main/java/dev/zoriya/omni/EventMap.kt @@ -0,0 +1,89 @@ +package dev.zoriya.omni + +import com.margelo.nitro.omni.HybridOmniEventMapSpec +import com.margelo.nitro.omni.Rendition +import com.margelo.nitro.omni.Track +import org.videolan.libvlc.MediaPlayer + +class EventMap(val player: MediaPlayer) : HybridOmniEventMapSpec(), MediaPlayer.EventListener { + init { + player.setEventListener(this) + } + + override fun onEvent(event: MediaPlayer.Event) { + when (event) { + + } + } + + override fun addOnEndListener(cb: () -> Unit) { + } + + override fun removeOnEndListener(cb: () -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnPrevListener(cb: () -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnPrevListener(cb: () -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnNextListener(cb: () -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnNextListener(cb: () -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnErrorListener(cb: (type: String, message: String) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnErrorListener(cb: (type: String, message: String) -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnAudioFocusChangeListener(cb: (status: String) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnAudioFocusChangeListener(cb: (status: String) -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnVideoTrackChangeListener(cb: (track: Track) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnVideoTrackChangeListener(cb: (track: Track) -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnAudioTrackChangeListener(cb: (track: Track) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnAudioTrackChangeListener(cb: (track: Track) -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnSubtitleChangeListener(cb: (track: Track?) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnSubtitleChangeListener(cb: (track: Track?) -> Unit) { + TODO("Not yet implemented") + } + + override fun addOnRenditionChangeListener(cb: (rendition: Rendition) -> Unit) { + TODO("Not yet implemented") + } + + override fun removeOnRenditionChangeListener(cb: (rendition: Rendition) -> Unit) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt b/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt index e493513..64beafe 100644 --- a/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt +++ b/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt @@ -2,6 +2,7 @@ package dev.zoriya.omni import android.net.Uri import com.margelo.nitro.NitroModules +import com.margelo.nitro.omni.HybridOmniEventMapSpec import com.margelo.nitro.omni.Source import com.margelo.nitro.omni.HybridOmniPlayerSpec import com.margelo.nitro.omni.PlayerStatus @@ -19,6 +20,7 @@ object VlcConst { class OmniPlayer() : HybridOmniPlayerSpec() { val player = MediaPlayer(VlcConst.vlc) + override val eventMap = EventMap(player); override var source: Source by deferredObservable { _, _, new -> val src = new.src.firstOrNull()?.uri ?: return@deferredObservable diff --git a/biome.json b/biome.json index 4ecc066..d8a4a05 100644 --- a/biome.json +++ b/biome.json @@ -20,6 +20,8 @@ "noNonNullAssertion": "off" }, "correctness": { + "noUnusedVariables": "off", + "noUnusedFunctionParameters": "off", "useExhaustiveDependencies": { "level": "warn", "options": { diff --git a/nitrogen/generated/android/Omni+autolinking.cmake b/nitrogen/generated/android/Omni+autolinking.cmake index ab143fa..703ac7b 100644 --- a/nitrogen/generated/android/Omni+autolinking.cmake +++ b/nitrogen/generated/android/Omni+autolinking.cmake @@ -33,11 +33,13 @@ target_sources( # Autolinking Setup ../nitrogen/generated/android/OmniOnLoad.cpp # Shared Nitrogen C++ sources + ../nitrogen/generated/shared/c++/HybridOmniEventMapSpec.cpp ../nitrogen/generated/shared/c++/HybridOmniPlayerSpec.cpp ../nitrogen/generated/shared/c++/HybridOmniPlayerFactorySpec.cpp ../nitrogen/generated/shared/c++/HybridOmniViewSpec.cpp ../nitrogen/generated/shared/c++/views/HybridOmniViewComponent.cpp # Android-specific Nitrogen C++ sources + ../nitrogen/generated/android/c++/JHybridOmniEventMapSpec.cpp ../nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp ../nitrogen/generated/android/c++/JHybridOmniPlayerFactorySpec.cpp ../nitrogen/generated/android/c++/JHybridOmniViewSpec.cpp diff --git a/nitrogen/generated/android/OmniOnLoad.cpp b/nitrogen/generated/android/OmniOnLoad.cpp index c3be823..d747b34 100644 --- a/nitrogen/generated/android/OmniOnLoad.cpp +++ b/nitrogen/generated/android/OmniOnLoad.cpp @@ -15,6 +15,13 @@ #include #include +#include "JHybridOmniEventMapSpec.hpp" +#include "JFunc_void.hpp" +#include "JFunc_void_std__string_std__string.hpp" +#include "JFunc_void_std__string.hpp" +#include "JFunc_void_Track.hpp" +#include "JFunc_void_std__optional_Track_.hpp" +#include "JFunc_void_Rendition.hpp" #include "JHybridOmniPlayerSpec.hpp" #include "JHybridOmniPlayerFactorySpec.hpp" #include "JHybridOmniViewSpec.hpp" @@ -51,6 +58,13 @@ void registerAllNatives() { using namespace margelo::nitro::omni; // Register native JNI methods + margelo::nitro::omni::JHybridOmniEventMapSpec::CxxPart::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(); + margelo::nitro::omni::JFunc_void_Track_cxx::registerNatives(); + margelo::nitro::omni::JFunc_void_std__optional_Track__cxx::registerNatives(); + margelo::nitro::omni::JFunc_void_Rendition_cxx::registerNatives(); margelo::nitro::omni::JHybridOmniPlayerSpec::CxxPart::registerNatives(); margelo::nitro::omni::JHybridOmniPlayerFactorySpec::CxxPart::registerNatives(); margelo::nitro::omni::JHybridOmniViewSpec::CxxPart::registerNatives(); diff --git a/nitrogen/generated/android/c++/JFunc_void.hpp b/nitrogen/generated/android/c++/JFunc_void.hpp new file mode 100644 index 0000000..f18d6e1 --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void.hpp @@ -0,0 +1,75 @@ +/// +/// JFunc_void.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `() -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void;"; + + public: + /** + * Invokes the function this `JFunc_void` instance holds through JNI. + */ + void invoke() const { + static const auto method = javaClassStatic()->getMethod("invoke"); + method(self()); + } + }; + + /** + * An implementation of Func_void that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& func) { + return JFunc_void_cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_cxx` instance holds. + */ + void invoke_cxx() { + _func(); + } + + public: + [[nodiscard]] + inline const std::function& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_cxx(const std::function& func): _func(func) { } + + private: + friend HybridBase; + std::function _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JFunc_void_Rendition.hpp b/nitrogen/generated/android/c++/JFunc_void_Rendition.hpp new file mode 100644 index 0000000..2834248 --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void_Rendition.hpp @@ -0,0 +1,78 @@ +/// +/// JFunc_void_Rendition.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include "Rendition.hpp" +#include +#include +#include "JRendition.hpp" +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `(rendition: Rendition) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void_Rendition: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_Rendition;"; + + public: + /** + * Invokes the function this `JFunc_void_Rendition` instance holds through JNI. + */ + void invoke(const Rendition& rendition) const { + static const auto method = javaClassStatic()->getMethod /* rendition */)>("invoke"); + method(self(), JRendition::fromCpp(rendition)); + } + }; + + /** + * An implementation of Func_void_Rendition that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_Rendition_cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& func) { + return JFunc_void_Rendition_cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_Rendition_cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref rendition) { + _func(rendition->toCpp()); + } + + public: + [[nodiscard]] + inline const std::function& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_Rendition_cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_Rendition_cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_Rendition_cxx(const std::function& func): _func(func) { } + + private: + friend HybridBase; + std::function _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JFunc_void_Track.hpp b/nitrogen/generated/android/c++/JFunc_void_Track.hpp new file mode 100644 index 0000000..3e625b3 --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void_Track.hpp @@ -0,0 +1,79 @@ +/// +/// JFunc_void_Track.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include "Track.hpp" +#include +#include +#include "JTrack.hpp" +#include +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `(track: Track) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void_Track: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_Track;"; + + public: + /** + * Invokes the function this `JFunc_void_Track` instance holds through JNI. + */ + void invoke(const Track& track) const { + static const auto method = javaClassStatic()->getMethod /* track */)>("invoke"); + method(self(), JTrack::fromCpp(track)); + } + }; + + /** + * An implementation of Func_void_Track that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_Track_cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& func) { + return JFunc_void_Track_cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_Track_cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref track) { + _func(track->toCpp()); + } + + public: + [[nodiscard]] + inline const std::function& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_Track_cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_Track_cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_Track_cxx(const std::function& func): _func(func) { } + + private: + friend HybridBase; + std::function _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JFunc_void_std__optional_Track_.hpp b/nitrogen/generated/android/c++/JFunc_void_std__optional_Track_.hpp new file mode 100644 index 0000000..2c3c14f --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void_std__optional_Track_.hpp @@ -0,0 +1,79 @@ +/// +/// JFunc_void_std__optional_Track_.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include "Track.hpp" +#include +#include +#include +#include "JTrack.hpp" +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `(track: Track?) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void_std__optional_Track_: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__optional_Track_;"; + + public: + /** + * Invokes the function this `JFunc_void_std__optional_Track_` instance holds through JNI. + */ + void invoke(const std::optional& track) const { + static const auto method = javaClassStatic()->getMethod /* track */)>("invoke"); + method(self(), track.has_value() ? JTrack::fromCpp(track.value()) : nullptr); + } + }; + + /** + * An implementation of Func_void_std__optional_Track_ that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_std__optional_Track__cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& /* track */)>& func) { + return JFunc_void_std__optional_Track__cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_Track__cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref track) { + _func(track != nullptr ? std::make_optional(track->toCpp()) : std::nullopt); + } + + public: + [[nodiscard]] + inline const std::function& /* track */)>& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__optional_Track__cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__optional_Track__cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_std__optional_Track__cxx(const std::function& /* track */)>& func): _func(func) { } + + private: + friend HybridBase; + std::function& /* track */)> _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JFunc_void_std__string.hpp b/nitrogen/generated/android/c++/JFunc_void_std__string.hpp new file mode 100644 index 0000000..6f6ceed --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void_std__string.hpp @@ -0,0 +1,76 @@ +/// +/// JFunc_void_std__string.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include +#include +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `(status: String) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void_std__string: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__string;"; + + public: + /** + * Invokes the function this `JFunc_void_std__string` instance holds through JNI. + */ + void invoke(const std::string& status) const { + static const auto method = javaClassStatic()->getMethod /* status */)>("invoke"); + method(self(), jni::make_jstring(status)); + } + }; + + /** + * An implementation of Func_void_std__string that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_std__string_cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& func) { + return JFunc_void_std__string_cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref status) { + _func(status->toStdString()); + } + + public: + [[nodiscard]] + inline const std::function& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__string_cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_std__string_cxx(const std::function& func): _func(func) { } + + private: + friend HybridBase; + std::function _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp b/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp new file mode 100644 index 0000000..95e815a --- /dev/null +++ b/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp @@ -0,0 +1,76 @@ +/// +/// JFunc_void_std__string_std__string.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +#include +#include +#include + +namespace margelo::nitro::omni { + + using namespace facebook; + + /** + * Represents the Java/Kotlin callback `(type: String, message: String) -> Unit`. + * This can be passed around between C++ and Java/Kotlin. + */ + struct JFunc_void_std__string_std__string: public jni::JavaClass { + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__string_std__string;"; + + public: + /** + * Invokes the function this `JFunc_void_std__string_std__string` instance holds through JNI. + */ + void invoke(const std::string& type, const std::string& message) const { + static const auto method = javaClassStatic()->getMethod /* type */, jni::alias_ref /* message */)>("invoke"); + method(self(), jni::make_jstring(type), jni::make_jstring(message)); + } + }; + + /** + * An implementation of Func_void_std__string_std__string that is backed by a C++ implementation (using `std::function<...>`) + */ + class JFunc_void_std__string_std__string_cxx final: public jni::HybridClass { + public: + static jni::local_ref fromCpp(const std::function& func) { + return JFunc_void_std__string_std__string_cxx::newObjectCxxArgs(func); + } + + public: + /** + * Invokes the C++ `std::function<...>` this `JFunc_void_std__string_std__string_cxx` instance holds. + */ + void invoke_cxx(jni::alias_ref type, jni::alias_ref message) { + _func(type->toStdString(), message->toStdString()); + } + + public: + [[nodiscard]] + inline const std::function& getFunction() const { + return _func; + } + + public: + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/Func_void_std__string_std__string_cxx;"; + static void registerNatives() { + registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__string_std__string_cxx::invoke_cxx)}); + } + + private: + explicit JFunc_void_std__string_std__string_cxx(const std::function& func): _func(func) { } + + private: + friend HybridBase; + std::function _func; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.cpp b/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.cpp new file mode 100644 index 0000000..bae0a17 --- /dev/null +++ b/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.cpp @@ -0,0 +1,136 @@ +/// +/// JHybridOmniEventMapSpec.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include "JHybridOmniEventMapSpec.hpp" + +// Forward declaration of `Track` to properly resolve imports. +namespace margelo::nitro::omni { struct Track; } +// Forward declaration of `Rendition` to properly resolve imports. +namespace margelo::nitro::omni { struct Rendition; } + +#include +#include "JFunc_void.hpp" +#include +#include +#include "JFunc_void_std__string_std__string.hpp" +#include "JFunc_void_std__string.hpp" +#include "Track.hpp" +#include "JFunc_void_Track.hpp" +#include "JTrack.hpp" +#include +#include "JFunc_void_std__optional_Track_.hpp" +#include "Rendition.hpp" +#include "JFunc_void_Rendition.hpp" +#include "JRendition.hpp" + +namespace margelo::nitro::omni { + + std::shared_ptr JHybridOmniEventMapSpec::JavaPart::getJHybridOmniEventMapSpec() { + auto hybridObject = JHybridObject::JavaPart::getJHybridObject(); + auto castHybridObject = std::dynamic_pointer_cast(hybridObject); + if (castHybridObject == nullptr) [[unlikely]] { + throw std::runtime_error("Failed to downcast JHybridObject to JHybridOmniEventMapSpec!"); + } + return castHybridObject; + } + + jni::local_ref JHybridOmniEventMapSpec::CxxPart::initHybrid(jni::alias_ref jThis) { + return makeCxxInstance(jThis); + } + + std::shared_ptr JHybridOmniEventMapSpec::CxxPart::createHybridObject(const jni::local_ref& javaPart) { + auto castJavaPart = jni::dynamic_ref_cast(javaPart); + if (castJavaPart == nullptr) [[unlikely]] { + throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridOmniEventMapSpec::JavaPart!"); + } + return std::make_shared(castJavaPart); + } + + void JHybridOmniEventMapSpec::CxxPart::registerNatives() { + registerHybrid({ + makeNativeMethod("initHybrid", JHybridOmniEventMapSpec::CxxPart::initHybrid), + }); + } + + // Properties + + + // Methods + void JHybridOmniEventMapSpec::addOnEndListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnEndListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnEndListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnEndListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnPrevListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnPrevListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnPrevListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnPrevListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnNextListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnNextListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnNextListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnNextListener_cxx"); + method(_javaPart, JFunc_void_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnErrorListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnErrorListener_cxx"); + method(_javaPart, JFunc_void_std__string_std__string_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnErrorListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnErrorListener_cxx"); + method(_javaPart, JFunc_void_std__string_std__string_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnAudioFocusChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnAudioFocusChangeListener_cxx"); + method(_javaPart, JFunc_void_std__string_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnAudioFocusChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnAudioFocusChangeListener_cxx"); + method(_javaPart, JFunc_void_std__string_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnVideoTrackChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnVideoTrackChangeListener_cxx"); + method(_javaPart, JFunc_void_Track_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnVideoTrackChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnVideoTrackChangeListener_cxx"); + method(_javaPart, JFunc_void_Track_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnAudioTrackChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnAudioTrackChangeListener_cxx"); + method(_javaPart, JFunc_void_Track_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnAudioTrackChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnAudioTrackChangeListener_cxx"); + method(_javaPart, JFunc_void_Track_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnSubtitleChangeListener(const std::function& /* track */)>& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnSubtitleChangeListener_cxx"); + method(_javaPart, JFunc_void_std__optional_Track__cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnSubtitleChangeListener(const std::function& /* track */)>& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnSubtitleChangeListener_cxx"); + method(_javaPart, JFunc_void_std__optional_Track__cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::addOnRenditionChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("addOnRenditionChangeListener_cxx"); + method(_javaPart, JFunc_void_Rendition_cxx::fromCpp(cb)); + } + void JHybridOmniEventMapSpec::removeOnRenditionChangeListener(const std::function& cb) { + static const auto method = _javaPart->javaClassStatic()->getMethod /* cb */)>("removeOnRenditionChangeListener_cxx"); + method(_javaPart, JFunc_void_Rendition_cxx::fromCpp(cb)); + } + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.hpp b/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.hpp new file mode 100644 index 0000000..c0679ca --- /dev/null +++ b/nitrogen/generated/android/c++/JHybridOmniEventMapSpec.hpp @@ -0,0 +1,80 @@ +/// +/// HybridOmniEventMapSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include "HybridOmniEventMapSpec.hpp" + + + + +namespace margelo::nitro::omni { + + using namespace facebook; + + class JHybridOmniEventMapSpec: public virtual HybridOmniEventMapSpec, public virtual JHybridObject { + public: + struct JavaPart: public jni::JavaClass { + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/HybridOmniEventMapSpec;"; + std::shared_ptr getJHybridOmniEventMapSpec(); + }; + struct CxxPart: public jni::HybridClass { + static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/HybridOmniEventMapSpec$CxxPart;"; + static jni::local_ref initHybrid(jni::alias_ref jThis); + static void registerNatives(); + using HybridBase::HybridBase; + protected: + std::shared_ptr createHybridObject(const jni::local_ref& javaPart) override; + }; + + public: + explicit JHybridOmniEventMapSpec(const jni::local_ref& javaPart): + HybridObject(HybridOmniEventMapSpec::TAG), + JHybridObject(javaPart), + _javaPart(jni::make_global(javaPart)) {} + ~JHybridOmniEventMapSpec() override { + // Hermes GC can destroy JS objects on a non-JNI Thread. + jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); + } + + public: + inline const jni::global_ref& getJavaPart() const noexcept { + return _javaPart; + } + + public: + // Properties + + + public: + // Methods + void addOnEndListener(const std::function& cb) override; + void removeOnEndListener(const std::function& cb) override; + void addOnPrevListener(const std::function& cb) override; + void removeOnPrevListener(const std::function& cb) override; + void addOnNextListener(const std::function& cb) override; + void removeOnNextListener(const std::function& cb) override; + void addOnErrorListener(const std::function& cb) override; + void removeOnErrorListener(const std::function& cb) override; + void addOnAudioFocusChangeListener(const std::function& cb) override; + void removeOnAudioFocusChangeListener(const std::function& cb) override; + void addOnVideoTrackChangeListener(const std::function& cb) override; + void removeOnVideoTrackChangeListener(const std::function& cb) override; + void addOnAudioTrackChangeListener(const std::function& cb) override; + void removeOnAudioTrackChangeListener(const std::function& cb) override; + void addOnSubtitleChangeListener(const std::function& /* track */)>& cb) override; + void removeOnSubtitleChangeListener(const std::function& /* track */)>& cb) override; + void addOnRenditionChangeListener(const std::function& cb) override; + void removeOnRenditionChangeListener(const std::function& cb) override; + + private: + jni::global_ref _javaPart; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp index 327fbc0..3f42e79 100644 --- a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp +++ b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp @@ -7,6 +7,8 @@ #include "JHybridOmniPlayerSpec.hpp" +// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports. +namespace margelo::nitro::omni { class HybridOmniEventMapSpec; } // Forward declaration of `Source` to properly resolve imports. namespace margelo::nitro::omni { struct Source; } // Forward declaration of `VideoSrc` to properly resolve imports. @@ -17,13 +19,16 @@ namespace margelo::nitro::omni { struct Subtitle; } namespace margelo::nitro::omni { struct Metadata; } // Forward declaration of `MixAudioMode` to properly resolve imports. namespace margelo::nitro::omni { enum class MixAudioMode; } -// Forward declaration of `PlayerStatus` to properly resolve imports. -namespace margelo::nitro::omni { enum class PlayerStatus; } // Forward declaration of `Track` to properly resolve imports. namespace margelo::nitro::omni { struct Track; } // Forward declaration of `Rendition` to properly resolve imports. namespace margelo::nitro::omni { struct Rendition; } +// Forward declaration of `PlayerStatus` to properly resolve imports. +namespace margelo::nitro::omni { enum class PlayerStatus; } +#include +#include "HybridOmniEventMapSpec.hpp" +#include "JHybridOmniEventMapSpec.hpp" #include "Source.hpp" #include "JSource.hpp" #include "VideoSrc.hpp" @@ -38,12 +43,12 @@ namespace margelo::nitro::omni { struct Rendition; } #include "JMetadata.hpp" #include "MixAudioMode.hpp" #include "JMixAudioMode.hpp" -#include "PlayerStatus.hpp" -#include "JPlayerStatus.hpp" #include "Track.hpp" #include "JTrack.hpp" #include "Rendition.hpp" #include "JRendition.hpp" +#include "PlayerStatus.hpp" +#include "JPlayerStatus.hpp" namespace margelo::nitro::omni { @@ -75,6 +80,11 @@ namespace margelo::nitro::omni { } // Properties + std::shared_ptr JHybridOmniPlayerSpec::getEventMap() { + static const auto method = _javaPart->javaClassStatic()->getMethod()>("getEventMap"); + auto __result = method(_javaPart); + return __result->getJHybridOmniEventMapSpec(); + } Source JHybridOmniPlayerSpec::getSource() { static const auto method = _javaPart->javaClassStatic()->getMethod()>("getSource"); auto __result = method(_javaPart); @@ -94,53 +104,6 @@ namespace margelo::nitro::omni { auto __result = method(_javaPart); return static_cast(__result); } - PlayerStatus JHybridOmniPlayerSpec::getStatus() { - static const auto method = _javaPart->javaClassStatic()->getMethod()>("getStatus"); - auto __result = method(_javaPart); - return __result->toCpp(); - } - bool JHybridOmniPlayerSpec::getIsPlaying() { - static const auto method = _javaPart->javaClassStatic()->getMethod("isPlaying"); - auto __result = method(_javaPart); - return static_cast(__result); - } - double JHybridOmniPlayerSpec::getCurrentTime() { - static const auto method = _javaPart->javaClassStatic()->getMethod("getCurrentTime"); - auto __result = method(_javaPart); - return __result; - } - void JHybridOmniPlayerSpec::setCurrentTime(double currentTime) { - static const auto method = _javaPart->javaClassStatic()->getMethod("setCurrentTime"); - method(_javaPart, currentTime); - } - double JHybridOmniPlayerSpec::getBuffered() { - static const auto method = _javaPart->javaClassStatic()->getMethod("getBuffered"); - auto __result = method(_javaPart); - return __result; - } - double JHybridOmniPlayerSpec::getDuration() { - static const auto method = _javaPart->javaClassStatic()->getMethod("getDuration"); - auto __result = method(_javaPart); - return __result; - } - double JHybridOmniPlayerSpec::getPlaybackRate() { - static const auto method = _javaPart->javaClassStatic()->getMethod("getPlaybackRate"); - auto __result = method(_javaPart); - return __result; - } - void JHybridOmniPlayerSpec::setPlaybackRate(double playbackRate) { - static const auto method = _javaPart->javaClassStatic()->getMethod("setPlaybackRate"); - method(_javaPart, playbackRate); - } - double JHybridOmniPlayerSpec::getVolume() { - static const auto method = _javaPart->javaClassStatic()->getMethod("getVolume"); - auto __result = method(_javaPart); - return __result; - } - void JHybridOmniPlayerSpec::setVolume(double volume) { - static const auto method = _javaPart->javaClassStatic()->getMethod("setVolume"); - method(_javaPart, volume); - } std::vector JHybridOmniPlayerSpec::getVideos() { static const auto method = _javaPart->javaClassStatic()->getMethod>()>("getVideos"); auto __result = method(_javaPart); @@ -197,6 +160,53 @@ namespace margelo::nitro::omni { return __vector; }(); } + PlayerStatus JHybridOmniPlayerSpec::getStatus() { + static const auto method = _javaPart->javaClassStatic()->getMethod()>("getStatus"); + auto __result = method(_javaPart); + return __result->toCpp(); + } + bool JHybridOmniPlayerSpec::getIsPlaying() { + static const auto method = _javaPart->javaClassStatic()->getMethod("isPlaying"); + auto __result = method(_javaPart); + return static_cast(__result); + } + double JHybridOmniPlayerSpec::getCurrentTime() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getCurrentTime"); + auto __result = method(_javaPart); + return __result; + } + void JHybridOmniPlayerSpec::setCurrentTime(double currentTime) { + static const auto method = _javaPart->javaClassStatic()->getMethod("setCurrentTime"); + method(_javaPart, currentTime); + } + double JHybridOmniPlayerSpec::getBuffered() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getBuffered"); + auto __result = method(_javaPart); + return __result; + } + double JHybridOmniPlayerSpec::getDuration() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getDuration"); + auto __result = method(_javaPart); + return __result; + } + double JHybridOmniPlayerSpec::getPlaybackRate() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getPlaybackRate"); + auto __result = method(_javaPart); + return __result; + } + void JHybridOmniPlayerSpec::setPlaybackRate(double playbackRate) { + static const auto method = _javaPart->javaClassStatic()->getMethod("setPlaybackRate"); + method(_javaPart, playbackRate); + } + double JHybridOmniPlayerSpec::getVolume() { + static const auto method = _javaPart->javaClassStatic()->getMethod("getVolume"); + auto __result = method(_javaPart); + return __result; + } + void JHybridOmniPlayerSpec::setVolume(double volume) { + static const auto method = _javaPart->javaClassStatic()->getMethod("setVolume"); + method(_javaPart, volume); + } // Methods void JHybridOmniPlayerSpec::play() { diff --git a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.hpp b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.hpp index a90a57b..9973571 100644 --- a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.hpp +++ b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.hpp @@ -50,10 +50,15 @@ namespace margelo::nitro::omni { public: // Properties + std::shared_ptr getEventMap() override; Source getSource() override; void setSource(const Source& source) override; bool getHasPrev() override; bool getHasNext() override; + std::vector getVideos() override; + std::vector getAudios() override; + std::vector getSubtitles() override; + std::vector getRendition() override; PlayerStatus getStatus() override; bool getIsPlaying() override; double getCurrentTime() override; @@ -64,10 +69,6 @@ namespace margelo::nitro::omni { void setPlaybackRate(double playbackRate) override; double getVolume() override; void setVolume(double volume) override; - std::vector getVideos() override; - std::vector getAudios() override; - std::vector getSubtitles() override; - std::vector getRendition() override; public: // Methods diff --git a/nitrogen/generated/android/c++/JPlayerStatus.hpp b/nitrogen/generated/android/c++/JPlayerStatus.hpp index e83fc25..e2fe11a 100644 --- a/nitrogen/generated/android/c++/JPlayerStatus.hpp +++ b/nitrogen/generated/android/c++/JPlayerStatus.hpp @@ -42,6 +42,9 @@ namespace margelo::nitro::omni { static jni::alias_ref fromCpp(PlayerStatus value) { static const auto clazz = javaClassStatic(); switch (value) { + case PlayerStatus::ERROR: + static const auto fieldERROR = clazz->getStaticField("ERROR"); + return clazz->getStaticFieldValue(fieldERROR); case PlayerStatus::IDLE: static const auto fieldIDLE = clazz->getStaticField("IDLE"); return clazz->getStaticFieldValue(fieldIDLE); @@ -51,9 +54,6 @@ namespace margelo::nitro::omni { case PlayerStatus::READYTOPLAY: static const auto fieldREADYTOPLAY = clazz->getStaticField("READYTOPLAY"); return clazz->getStaticFieldValue(fieldREADYTOPLAY); - case PlayerStatus::ERROR: - static const auto fieldERROR = clazz->getStaticField("ERROR"); - return clazz->getStaticFieldValue(fieldERROR); default: std::string stringValue = std::to_string(static_cast(value)); throw std::invalid_argument("Invalid enum value (" + stringValue + "!"); diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void.kt new file mode 100644 index 0000000..53700ea --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void.kt @@ -0,0 +1,80 @@ +/// +/// Func_void.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 `() => 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: () -> 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(): Unit +} + +/** + * Represents the JavaScript callback `() => 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_cxx: Func_void { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(): Unit + = invoke_cxx() + + @FastNative + private external fun invoke_cxx(): Unit +} + +/** + * Represents the JavaScript callback `() => void`. + * This is implemented in Java/Kotlin, via a `() -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_java(private val function: () -> Unit): Func_void { + @DoNotStrip + @Keep + override fun invoke(): Unit { + return this.function() + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Rendition.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Rendition.kt new file mode 100644 index 0000000..eef1845 --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Rendition.kt @@ -0,0 +1,80 @@ +/// +/// Func_void_Rendition.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 `(rendition: struct) => 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_Rendition: (Rendition) -> 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(rendition: Rendition): Unit +} + +/** + * Represents the JavaScript callback `(rendition: struct) => 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_Rendition_cxx: Func_void_Rendition { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(rendition: Rendition): Unit + = invoke_cxx(rendition) + + @FastNative + private external fun invoke_cxx(rendition: Rendition): Unit +} + +/** + * Represents the JavaScript callback `(rendition: struct) => void`. + * This is implemented in Java/Kotlin, via a `(Rendition) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_Rendition_java(private val function: (Rendition) -> Unit): Func_void_Rendition { + @DoNotStrip + @Keep + override fun invoke(rendition: Rendition): Unit { + return this.function(rendition) + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Track.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Track.kt new file mode 100644 index 0000000..dddd8d6 --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_Track.kt @@ -0,0 +1,80 @@ +/// +/// Func_void_Track.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 `(track: struct) => 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_Track: (Track) -> 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(track: Track): Unit +} + +/** + * Represents the JavaScript callback `(track: struct) => 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_Track_cxx: Func_void_Track { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(track: Track): Unit + = invoke_cxx(track) + + @FastNative + private external fun invoke_cxx(track: Track): Unit +} + +/** + * Represents the JavaScript callback `(track: struct) => void`. + * This is implemented in Java/Kotlin, via a `(Track) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_Track_java(private val function: (Track) -> Unit): Func_void_Track { + @DoNotStrip + @Keep + override fun invoke(track: Track): Unit { + return this.function(track) + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__optional_Track_.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__optional_Track_.kt new file mode 100644 index 0000000..ec49c01 --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__optional_Track_.kt @@ -0,0 +1,80 @@ +/// +/// Func_void_std__optional_Track_.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 `(track: optional) => 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_std__optional_Track_: (Track?) -> 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(track: Track?): Unit +} + +/** + * Represents the JavaScript callback `(track: optional) => 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_std__optional_Track__cxx: Func_void_std__optional_Track_ { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(track: Track?): Unit + = invoke_cxx(track) + + @FastNative + private external fun invoke_cxx(track: Track?): Unit +} + +/** + * Represents the JavaScript callback `(track: optional) => void`. + * This is implemented in Java/Kotlin, via a `(Track?) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__optional_Track__java(private val function: (Track?) -> Unit): Func_void_std__optional_Track_ { + @DoNotStrip + @Keep + override fun invoke(track: Track?): Unit { + return this.function(track) + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string.kt new file mode 100644 index 0000000..4200567 --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string.kt @@ -0,0 +1,80 @@ +/// +/// Func_void_std__string.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 `(status: string) => 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_std__string: (String) -> 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(status: String): Unit +} + +/** + * Represents the JavaScript callback `(status: string) => 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_std__string_cxx: Func_void_std__string { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(status: String): Unit + = invoke_cxx(status) + + @FastNative + private external fun invoke_cxx(status: String): Unit +} + +/** + * Represents the JavaScript callback `(status: string) => void`. + * This is implemented in Java/Kotlin, via a `(String) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__string_java(private val function: (String) -> Unit): Func_void_std__string { + @DoNotStrip + @Keep + override fun invoke(status: String): Unit { + return this.function(status) + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string_std__string.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string_std__string.kt new file mode 100644 index 0000000..ac928fd --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Func_void_std__string_std__string.kt @@ -0,0 +1,80 @@ +/// +/// Func_void_std__string_std__string.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 `(type: string, message: string) => 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_std__string_std__string: (String, String) -> 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(type: String, message: String): Unit +} + +/** + * Represents the JavaScript callback `(type: string, message: string) => 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_std__string_std__string_cxx: Func_void_std__string_std__string { + @DoNotStrip + @Keep + private val mHybridData: HybridData + + @DoNotStrip + @Keep + private constructor(hybridData: HybridData) { + mHybridData = hybridData + } + + @DoNotStrip + @Keep + override fun invoke(type: String, message: String): Unit + = invoke_cxx(type,message) + + @FastNative + private external fun invoke_cxx(type: String, message: String): Unit +} + +/** + * Represents the JavaScript callback `(type: string, message: string) => void`. + * This is implemented in Java/Kotlin, via a `(String, String) -> Unit`. + * The callback is always coming from native. + */ +@DoNotStrip +@Keep +@Suppress("ClassName", "RedundantUnitReturnType", "unused") +class Func_void_std__string_std__string_java(private val function: (String, String) -> Unit): Func_void_std__string_std__string { + @DoNotStrip + @Keep + override fun invoke(type: String, message: String): Unit { + return this.function(type, message) + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniEventMapSpec.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniEventMapSpec.kt new file mode 100644 index 0000000..33ad173 --- /dev/null +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniEventMapSpec.kt @@ -0,0 +1,212 @@ +/// +/// HybridOmniEventMapSpec.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 com.margelo.nitro.core.HybridObject + +/** + * A Kotlin class representing the OmniEventMap HybridObject. + * Implement this abstract class to create Kotlin-based instances of OmniEventMap. + */ +@DoNotStrip +@Keep +@Suppress( + "KotlinJniMissingFunction", "unused", + "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet", + "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName" +) +abstract class HybridOmniEventMapSpec: HybridObject() { + // Properties + + + // Methods + abstract fun addOnEndListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnEndListener_cxx(cb: Func_void): Unit { + val __result = addOnEndListener(cb) + return __result + } + + abstract fun removeOnEndListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnEndListener_cxx(cb: Func_void): Unit { + val __result = removeOnEndListener(cb) + return __result + } + + abstract fun addOnPrevListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnPrevListener_cxx(cb: Func_void): Unit { + val __result = addOnPrevListener(cb) + return __result + } + + abstract fun removeOnPrevListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnPrevListener_cxx(cb: Func_void): Unit { + val __result = removeOnPrevListener(cb) + return __result + } + + abstract fun addOnNextListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnNextListener_cxx(cb: Func_void): Unit { + val __result = addOnNextListener(cb) + return __result + } + + abstract fun removeOnNextListener(cb: () -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnNextListener_cxx(cb: Func_void): Unit { + val __result = removeOnNextListener(cb) + return __result + } + + abstract fun addOnErrorListener(cb: (type: String, message: String) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnErrorListener_cxx(cb: Func_void_std__string_std__string): Unit { + val __result = addOnErrorListener(cb) + return __result + } + + abstract fun removeOnErrorListener(cb: (type: String, message: String) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnErrorListener_cxx(cb: Func_void_std__string_std__string): Unit { + val __result = removeOnErrorListener(cb) + return __result + } + + abstract fun addOnAudioFocusChangeListener(cb: (status: String) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnAudioFocusChangeListener_cxx(cb: Func_void_std__string): Unit { + val __result = addOnAudioFocusChangeListener(cb) + return __result + } + + abstract fun removeOnAudioFocusChangeListener(cb: (status: String) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnAudioFocusChangeListener_cxx(cb: Func_void_std__string): Unit { + val __result = removeOnAudioFocusChangeListener(cb) + return __result + } + + abstract fun addOnVideoTrackChangeListener(cb: (track: Track) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnVideoTrackChangeListener_cxx(cb: Func_void_Track): Unit { + val __result = addOnVideoTrackChangeListener(cb) + return __result + } + + abstract fun removeOnVideoTrackChangeListener(cb: (track: Track) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnVideoTrackChangeListener_cxx(cb: Func_void_Track): Unit { + val __result = removeOnVideoTrackChangeListener(cb) + return __result + } + + abstract fun addOnAudioTrackChangeListener(cb: (track: Track) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnAudioTrackChangeListener_cxx(cb: Func_void_Track): Unit { + val __result = addOnAudioTrackChangeListener(cb) + return __result + } + + abstract fun removeOnAudioTrackChangeListener(cb: (track: Track) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnAudioTrackChangeListener_cxx(cb: Func_void_Track): Unit { + val __result = removeOnAudioTrackChangeListener(cb) + return __result + } + + abstract fun addOnSubtitleChangeListener(cb: (track: Track?) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnSubtitleChangeListener_cxx(cb: Func_void_std__optional_Track_): Unit { + val __result = addOnSubtitleChangeListener(cb) + return __result + } + + abstract fun removeOnSubtitleChangeListener(cb: (track: Track?) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnSubtitleChangeListener_cxx(cb: Func_void_std__optional_Track_): Unit { + val __result = removeOnSubtitleChangeListener(cb) + return __result + } + + abstract fun addOnRenditionChangeListener(cb: (rendition: Rendition) -> Unit): Unit + + @DoNotStrip + @Keep + private fun addOnRenditionChangeListener_cxx(cb: Func_void_Rendition): Unit { + val __result = addOnRenditionChangeListener(cb) + return __result + } + + abstract fun removeOnRenditionChangeListener(cb: (rendition: Rendition) -> Unit): Unit + + @DoNotStrip + @Keep + private fun removeOnRenditionChangeListener_cxx(cb: Func_void_Rendition): Unit { + val __result = removeOnRenditionChangeListener(cb) + return __result + } + + // Default implementation of `HybridObject.toString()` + override fun toString(): String { + return "[HybridObject OmniEventMap]" + } + + // C++ backing class + @DoNotStrip + @Keep + protected open class CxxPart(javaPart: HybridOmniEventMapSpec): HybridObject.CxxPart(javaPart) { + // C++ JHybridOmniEventMapSpec::CxxPart::initHybrid(...) + external override fun initHybrid(): HybridData + } + override fun createCxxPart(): CxxPart { + return CxxPart(this) + } + + companion object { + protected const val TAG = "HybridOmniEventMapSpec" + } +} diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniPlayerSpec.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniPlayerSpec.kt index 428a7c8..aee8b37 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniPlayerSpec.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/HybridOmniPlayerSpec.kt @@ -25,6 +25,10 @@ import com.margelo.nitro.core.HybridObject ) abstract class HybridOmniPlayerSpec: HybridObject() { // Properties + @get:DoNotStrip + @get:Keep + abstract val eventMap: HybridOmniEventMapSpec + @get:DoNotStrip @get:Keep @set:DoNotStrip @@ -39,6 +43,22 @@ abstract class HybridOmniPlayerSpec: HybridObject() { @get:Keep abstract val hasNext: Boolean + @get:DoNotStrip + @get:Keep + abstract val videos: Array + + @get:DoNotStrip + @get:Keep + abstract val audios: Array + + @get:DoNotStrip + @get:Keep + abstract val subtitles: Array + + @get:DoNotStrip + @get:Keep + abstract val rendition: Array + @get:DoNotStrip @get:Keep abstract val status: PlayerStatus @@ -72,22 +92,6 @@ abstract class HybridOmniPlayerSpec: HybridObject() { @set:DoNotStrip @set:Keep abstract var volume: Double - - @get:DoNotStrip - @get:Keep - abstract val videos: Array - - @get:DoNotStrip - @get:Keep - abstract val audios: Array - - @get:DoNotStrip - @get:Keep - abstract val subtitles: Array - - @get:DoNotStrip - @get:Keep - abstract val rendition: Array // Methods @DoNotStrip diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/PlayerStatus.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/PlayerStatus.kt index 3dbe080..c7207fe 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/PlayerStatus.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/PlayerStatus.kt @@ -16,10 +16,10 @@ import com.facebook.proguard.annotations.DoNotStrip @DoNotStrip @Keep enum class PlayerStatus(@DoNotStrip @Keep val value: Int) { - IDLE(0), - LOADING(1), - READYTOPLAY(2), - ERROR(3); + ERROR(0), + IDLE(1), + LOADING(2), + READYTOPLAY(3); companion object } diff --git a/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.cpp b/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.cpp new file mode 100644 index 0000000..f41c5ec --- /dev/null +++ b/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.cpp @@ -0,0 +1,38 @@ +/// +/// HybridOmniEventMapSpec.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include "HybridOmniEventMapSpec.hpp" + +namespace margelo::nitro::omni { + + void HybridOmniEventMapSpec::loadHybridMethods() { + // load base methods/properties + HybridObject::loadHybridMethods(); + // load custom methods/properties + registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridMethod("addOnEndListener", &HybridOmniEventMapSpec::addOnEndListener); + prototype.registerHybridMethod("removeOnEndListener", &HybridOmniEventMapSpec::removeOnEndListener); + prototype.registerHybridMethod("addOnPrevListener", &HybridOmniEventMapSpec::addOnPrevListener); + prototype.registerHybridMethod("removeOnPrevListener", &HybridOmniEventMapSpec::removeOnPrevListener); + prototype.registerHybridMethod("addOnNextListener", &HybridOmniEventMapSpec::addOnNextListener); + prototype.registerHybridMethod("removeOnNextListener", &HybridOmniEventMapSpec::removeOnNextListener); + prototype.registerHybridMethod("addOnErrorListener", &HybridOmniEventMapSpec::addOnErrorListener); + prototype.registerHybridMethod("removeOnErrorListener", &HybridOmniEventMapSpec::removeOnErrorListener); + prototype.registerHybridMethod("addOnAudioFocusChangeListener", &HybridOmniEventMapSpec::addOnAudioFocusChangeListener); + prototype.registerHybridMethod("removeOnAudioFocusChangeListener", &HybridOmniEventMapSpec::removeOnAudioFocusChangeListener); + prototype.registerHybridMethod("addOnVideoTrackChangeListener", &HybridOmniEventMapSpec::addOnVideoTrackChangeListener); + prototype.registerHybridMethod("removeOnVideoTrackChangeListener", &HybridOmniEventMapSpec::removeOnVideoTrackChangeListener); + prototype.registerHybridMethod("addOnAudioTrackChangeListener", &HybridOmniEventMapSpec::addOnAudioTrackChangeListener); + prototype.registerHybridMethod("removeOnAudioTrackChangeListener", &HybridOmniEventMapSpec::removeOnAudioTrackChangeListener); + prototype.registerHybridMethod("addOnSubtitleChangeListener", &HybridOmniEventMapSpec::addOnSubtitleChangeListener); + prototype.registerHybridMethod("removeOnSubtitleChangeListener", &HybridOmniEventMapSpec::removeOnSubtitleChangeListener); + prototype.registerHybridMethod("addOnRenditionChangeListener", &HybridOmniEventMapSpec::addOnRenditionChangeListener); + prototype.registerHybridMethod("removeOnRenditionChangeListener", &HybridOmniEventMapSpec::removeOnRenditionChangeListener); + }); + } + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.hpp b/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.hpp new file mode 100644 index 0000000..e93665c --- /dev/null +++ b/nitrogen/generated/shared/c++/HybridOmniEventMapSpec.hpp @@ -0,0 +1,86 @@ +/// +/// HybridOmniEventMapSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#if __has_include() +#include +#else +#error NitroModules cannot be found! Are you sure you installed NitroModules properly? +#endif + +// Forward declaration of `Track` to properly resolve imports. +namespace margelo::nitro::omni { struct Track; } +// Forward declaration of `Rendition` to properly resolve imports. +namespace margelo::nitro::omni { struct Rendition; } + +#include +#include +#include "Track.hpp" +#include +#include "Rendition.hpp" + +namespace margelo::nitro::omni { + + using namespace margelo::nitro; + + /** + * An abstract base class for `OmniEventMap` + * Inherit this class to create instances of `HybridOmniEventMapSpec` in C++. + * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. + * @example + * ```cpp + * class HybridOmniEventMap: public HybridOmniEventMapSpec { + * public: + * HybridOmniEventMap(...): HybridObject(TAG) { ... } + * // ... + * }; + * ``` + */ + class HybridOmniEventMapSpec: public virtual HybridObject { + public: + // Constructor + explicit HybridOmniEventMapSpec(): HybridObject(TAG) { } + + // Destructor + ~HybridOmniEventMapSpec() override = default; + + public: + // Properties + + + public: + // Methods + virtual void addOnEndListener(const std::function& cb) = 0; + virtual void removeOnEndListener(const std::function& cb) = 0; + virtual void addOnPrevListener(const std::function& cb) = 0; + virtual void removeOnPrevListener(const std::function& cb) = 0; + virtual void addOnNextListener(const std::function& cb) = 0; + virtual void removeOnNextListener(const std::function& cb) = 0; + virtual void addOnErrorListener(const std::function& cb) = 0; + virtual void removeOnErrorListener(const std::function& cb) = 0; + virtual void addOnAudioFocusChangeListener(const std::function& cb) = 0; + virtual void removeOnAudioFocusChangeListener(const std::function& cb) = 0; + virtual void addOnVideoTrackChangeListener(const std::function& cb) = 0; + virtual void removeOnVideoTrackChangeListener(const std::function& cb) = 0; + virtual void addOnAudioTrackChangeListener(const std::function& cb) = 0; + virtual void removeOnAudioTrackChangeListener(const std::function& cb) = 0; + virtual void addOnSubtitleChangeListener(const std::function& /* track */)>& cb) = 0; + virtual void removeOnSubtitleChangeListener(const std::function& /* track */)>& cb) = 0; + virtual void addOnRenditionChangeListener(const std::function& cb) = 0; + virtual void removeOnRenditionChangeListener(const std::function& cb) = 0; + + protected: + // Hybrid Setup + void loadHybridMethods() override; + + protected: + // Tag for logging + static constexpr auto TAG = "OmniEventMap"; + }; + +} // namespace margelo::nitro::omni diff --git a/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.cpp b/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.cpp index 719aed8..faf6d56 100644 --- a/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.cpp +++ b/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.cpp @@ -14,10 +14,15 @@ namespace margelo::nitro::omni { HybridObject::loadHybridMethods(); // load custom methods/properties registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridGetter("eventMap", &HybridOmniPlayerSpec::getEventMap); prototype.registerHybridGetter("source", &HybridOmniPlayerSpec::getSource); prototype.registerHybridSetter("source", &HybridOmniPlayerSpec::setSource); prototype.registerHybridGetter("hasPrev", &HybridOmniPlayerSpec::getHasPrev); prototype.registerHybridGetter("hasNext", &HybridOmniPlayerSpec::getHasNext); + prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos); + prototype.registerHybridGetter("audios", &HybridOmniPlayerSpec::getAudios); + prototype.registerHybridGetter("subtitles", &HybridOmniPlayerSpec::getSubtitles); + prototype.registerHybridGetter("rendition", &HybridOmniPlayerSpec::getRendition); prototype.registerHybridGetter("status", &HybridOmniPlayerSpec::getStatus); prototype.registerHybridGetter("isPlaying", &HybridOmniPlayerSpec::getIsPlaying); prototype.registerHybridGetter("currentTime", &HybridOmniPlayerSpec::getCurrentTime); @@ -28,10 +33,6 @@ namespace margelo::nitro::omni { prototype.registerHybridSetter("playbackRate", &HybridOmniPlayerSpec::setPlaybackRate); prototype.registerHybridGetter("volume", &HybridOmniPlayerSpec::getVolume); prototype.registerHybridSetter("volume", &HybridOmniPlayerSpec::setVolume); - prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos); - prototype.registerHybridGetter("audios", &HybridOmniPlayerSpec::getAudios); - prototype.registerHybridGetter("subtitles", &HybridOmniPlayerSpec::getSubtitles); - prototype.registerHybridGetter("rendition", &HybridOmniPlayerSpec::getRendition); prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play); prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause); prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy); diff --git a/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.hpp b/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.hpp index fcf20b6..8ebfaf4 100644 --- a/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.hpp +++ b/nitrogen/generated/shared/c++/HybridOmniPlayerSpec.hpp @@ -13,20 +13,24 @@ #error NitroModules cannot be found! Are you sure you installed NitroModules properly? #endif +// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports. +namespace margelo::nitro::omni { class HybridOmniEventMapSpec; } // Forward declaration of `Source` to properly resolve imports. namespace margelo::nitro::omni { struct Source; } -// Forward declaration of `PlayerStatus` to properly resolve imports. -namespace margelo::nitro::omni { enum class PlayerStatus; } // Forward declaration of `Track` to properly resolve imports. namespace margelo::nitro::omni { struct Track; } // Forward declaration of `Rendition` to properly resolve imports. namespace margelo::nitro::omni { struct Rendition; } +// Forward declaration of `PlayerStatus` to properly resolve imports. +namespace margelo::nitro::omni { enum class PlayerStatus; } +#include +#include "HybridOmniEventMapSpec.hpp" #include "Source.hpp" -#include "PlayerStatus.hpp" #include "Track.hpp" #include #include "Rendition.hpp" +#include "PlayerStatus.hpp" #include namespace margelo::nitro::omni { @@ -56,10 +60,15 @@ namespace margelo::nitro::omni { public: // Properties + virtual std::shared_ptr getEventMap() = 0; virtual Source getSource() = 0; virtual void setSource(const Source& source) = 0; virtual bool getHasPrev() = 0; virtual bool getHasNext() = 0; + virtual std::vector getVideos() = 0; + virtual std::vector getAudios() = 0; + virtual std::vector getSubtitles() = 0; + virtual std::vector getRendition() = 0; virtual PlayerStatus getStatus() = 0; virtual bool getIsPlaying() = 0; virtual double getCurrentTime() = 0; @@ -70,10 +79,6 @@ namespace margelo::nitro::omni { virtual void setPlaybackRate(double playbackRate) = 0; virtual double getVolume() = 0; virtual void setVolume(double volume) = 0; - virtual std::vector getVideos() = 0; - virtual std::vector getAudios() = 0; - virtual std::vector getSubtitles() = 0; - virtual std::vector getRendition() = 0; public: // Methods diff --git a/nitrogen/generated/shared/c++/PlayerStatus.hpp b/nitrogen/generated/shared/c++/PlayerStatus.hpp index 396ab05..11053eb 100644 --- a/nitrogen/generated/shared/c++/PlayerStatus.hpp +++ b/nitrogen/generated/shared/c++/PlayerStatus.hpp @@ -29,10 +29,10 @@ namespace margelo::nitro::omni { * An enum which can be represented as a JavaScript union (PlayerStatus). */ enum class PlayerStatus { - IDLE SWIFT_NAME(idle) = 0, - LOADING SWIFT_NAME(loading) = 1, - READYTOPLAY SWIFT_NAME(readytoplay) = 2, - ERROR SWIFT_NAME(error) = 3, + ERROR SWIFT_NAME(error) = 0, + IDLE SWIFT_NAME(idle) = 1, + LOADING SWIFT_NAME(loading) = 2, + READYTOPLAY SWIFT_NAME(readytoplay) = 3, } CLOSED_ENUM; } // namespace margelo::nitro::omni @@ -45,20 +45,20 @@ namespace margelo::nitro { static inline margelo::nitro::omni::PlayerStatus fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { std::string unionValue = JSIConverter::fromJSI(runtime, arg); switch (hashString(unionValue.c_str(), unionValue.size())) { + case hashString("error"): return margelo::nitro::omni::PlayerStatus::ERROR; case hashString("idle"): return margelo::nitro::omni::PlayerStatus::IDLE; case hashString("loading"): return margelo::nitro::omni::PlayerStatus::LOADING; case hashString("readyToPlay"): return margelo::nitro::omni::PlayerStatus::READYTOPLAY; - case hashString("error"): return margelo::nitro::omni::PlayerStatus::ERROR; default: [[unlikely]] throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PlayerStatus - invalid value!"); } } static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::omni::PlayerStatus arg) { switch (arg) { + case margelo::nitro::omni::PlayerStatus::ERROR: return JSIConverter::toJSI(runtime, "error"); case margelo::nitro::omni::PlayerStatus::IDLE: return JSIConverter::toJSI(runtime, "idle"); case margelo::nitro::omni::PlayerStatus::LOADING: return JSIConverter::toJSI(runtime, "loading"); case margelo::nitro::omni::PlayerStatus::READYTOPLAY: return JSIConverter::toJSI(runtime, "readyToPlay"); - case margelo::nitro::omni::PlayerStatus::ERROR: return JSIConverter::toJSI(runtime, "error"); default: [[unlikely]] throw std::invalid_argument("Cannot convert PlayerStatus to JS - invalid value: " + std::to_string(static_cast(arg)) + "!"); @@ -70,10 +70,10 @@ namespace margelo::nitro { } std::string unionValue = JSIConverter::fromJSI(runtime, value); switch (hashString(unionValue.c_str(), unionValue.size())) { + case hashString("error"): case hashString("idle"): case hashString("loading"): case hashString("readyToPlay"): - case hashString("error"): return true; default: return false; diff --git a/src/events.tsx b/src/events.tsx new file mode 100644 index 0000000..ce47fe9 --- /dev/null +++ b/src/events.tsx @@ -0,0 +1,31 @@ +import { useEffect, useState } from "react"; +import { usePlayer } from "./provider"; +import type { OmniPlayer } from "./specs/omni-player.nitro"; +import type { OmniEvents } from "./types/events"; +import type { OmniPlayerState } from "./types/player"; + +function capitalize(str: T): Capitalize { + return (str.charAt(0).toUpperCase() + + str.slice(1).toLowerCase()) as Capitalize; +} + +export const useEvent = ( + event: Event, + callback: OmniEvents[Event], +) => { + const player = usePlayer() as OmniPlayer; + useEffect(() => { + player.eventMap[`addOn${capitalize(event)}Listener`](callback as any); + return () => + player.eventMap[`removeOn${capitalize(event)}Listener`](callback as any); + }, [player, event, callback]); +}; + +export const usePlayerState = ( + key: Key, +): OmniPlayerState[Key] => { + const player = usePlayer(); + const [ret, setState] = useState(player[key]); + // TODO: find a way to listen to that. + return ret; +}; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..5ebc89d --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export { OmniProvider, usePlayer } from "./provider"; +export { OmniView } from "./view"; diff --git a/src/specs/omni-player.nitro.ts b/src/specs/omni-player.nitro.ts index 09ec7b2..3da7399 100644 --- a/src/specs/omni-player.nitro.ts +++ b/src/specs/omni-player.nitro.ts @@ -1,10 +1,51 @@ import type { HybridObject } from "react-native-nitro-modules"; -import type { OmniPlayer as OmniPlayerT } from "../types/player"; +import type { OmniEvents } from "../types/events"; +import type { + OmniPlayerState, + OmniPlayer as OmniPlayerT, +} from "../types/player"; import type { Source } from "../types/source"; +export interface OmniEventMap extends HybridObject<{ android: "kotlin" }> { + addStateListener( + key: keyof OmniPlayerState, + cb: (value: number) => void, + ): void; + removeStateListener(cb: OmniEvents["end"]): void; + + addOnEndListener(cb: OmniEvents["end"]): void; + removeOnEndListener(cb: OmniEvents["end"]): void; + + addOnPrevListener(cb: OmniEvents["prev"]): void; + removeOnPrevListener(cb: OmniEvents["prev"]): void; + + addOnNextListener(cb: OmniEvents["next"]): void; + removeOnNextListener(cb: OmniEvents["next"]): void; + + addOnErrorListener(cb: OmniEvents["error"]): void; + removeOnErrorListener(cb: OmniEvents["error"]): void; + + addOnAudioFocusChangeListener(cb: OmniEvents["audioFocusChange"]): void; + removeOnAudioFocusChangeListener(cb: OmniEvents["audioFocusChange"]): void; + + addOnVideoTrackChangeListener(cb: OmniEvents["videoTrackChange"]): void; + removeOnVideoTrackChangeListener(cb: OmniEvents["videoTrackChange"]): void; + + addOnAudioTrackChangeListener(cb: OmniEvents["audioTrackChange"]): void; + removeOnAudioTrackChangeListener(cb: OmniEvents["audioTrackChange"]): void; + + addOnSubtitleChangeListener(cb: OmniEvents["subtitleChange"]): void; + removeOnSubtitleChangeListener(cb: OmniEvents["subtitleChange"]): void; + + addOnRenditionChangeListener(cb: OmniEvents["renditionChange"]): void; + removeOnRenditionChangeListener(cb: OmniEvents["renditionChange"]): void; +} + export interface OmniPlayer extends HybridObject<{ android: "kotlin" }>, - OmniPlayerT {} + OmniPlayerT { + readonly eventMap: OmniEventMap; +} export interface OmniPlayerFactory extends HybridObject<{ android: "kotlin" }> { createPlayer(props: Source): OmniPlayer; diff --git a/src/types/events.ts b/src/types/events.ts index 19382fe..5aaf608 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -1,3 +1,17 @@ +import type { Rendition, Track } from "./player"; + export interface OmniEvents { - onEnd: () => void; + end: () => void; + prev: () => void; + next: () => void; + error: (type: ErrorType, message: string) => void; + audioFocusChange: (status: AudioFocus) => void; + + videoTrackChange: (track: Track) => void; + audioTrackChange: (track: Track) => void; + subtitleChange: (track?: Track) => void; + renditionChange: (rendition: Rendition) => void; } + +export type ErrorType = string; +export type AudioFocus = string; diff --git a/src/types/player.ts b/src/types/player.ts index 27a173a..ea70c96 100644 --- a/src/types/player.ts +++ b/src/types/player.ts @@ -1,6 +1,6 @@ import type { Source } from "./source"; -export interface OmniPlayer { +export interface OmniPlayer extends OmniPlayerState { source: Source; play(): void; @@ -13,15 +13,6 @@ export interface OmniPlayer { readonly hasPrev: boolean; readonly hasNext: boolean; - readonly status: PlayerStatus; - readonly isPlaying: boolean; - currentTime: number; - readonly buffered: number; - readonly duration: number; - playbackRate: number; - // between 0 and 1 - volume: number; - readonly videos: Track[]; selectVideo(video: Track): void; readonly audios: Track[]; @@ -32,6 +23,17 @@ export interface OmniPlayer { selectRendition(rendition?: Rendition): void; } +export interface OmniPlayerState { + readonly status: PlayerStatus; + readonly isPlaying: boolean; + currentTime: number; + readonly buffered: number; + readonly duration: number; + playbackRate: number; + // between 0 and 1 + volume: number; +} + export type PlayerStatus = "idle" | "loading" | "readyToPlay" | "error"; export interface Track { diff --git a/tsconfig.json b/tsconfig.json index 67fe5f5..00d75f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,8 +15,6 @@ "noImplicitUseStrict": false, "noStrictGenericChecks": false, "noUncheckedIndexedAccess": true, - "noUnusedLocals": true, - "noUnusedParameters": true, "resolveJsonModule": true, "skipLibCheck": true, "strict": true,