From dc0627afb4147ca3f9da19f8388374e5919a3840 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 Jul 2026 19:33:51 +0200 Subject: [PATCH] fix(source): remove array syntax --- README.md | 2 +- .../main/java/dev/zoriya/omni/OmniPlayer.kt | 13 ++------- example/App.tsx | 10 +++---- .../c++/JHybridOmniPlayerFactorySpec.cpp | 2 +- .../android/c++/JHybridOmniPlayerSpec.cpp | 2 +- nitrogen/generated/android/c++/JSource.hpp | 28 ++++--------------- .../kotlin/com/margelo/nitro/omni/Source.kt | 4 +-- nitrogen/generated/shared/c++/Source.hpp | 12 ++++---- src/provider.web.tsx | 2 +- src/types/source.ts | 2 +- src/view.web.tsx | 2 +- 11 files changed, 26 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 02a3a0a..55282bb 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ function Player() { export default function App() { const source = { - src: [{ uri: "https://example.com/stream.m3u8", headers: {} }], + src: { uri: "https://example.com/stream.m3u8", headers: {} }, subtitles: [], metadata: { title: "My video", hasPrev: false, hasNext: true }, }; diff --git a/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt b/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt index 6ff754e..01dccd6 100644 --- a/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt +++ b/android/src/main/java/dev/zoriya/omni/OmniPlayer.kt @@ -290,18 +290,11 @@ class OmniPlayer( // audio focus only makes sense locally. not in a cast session runOnMainThread { localPlayer.setAudioAttributes(audioAttributes, handleAudioFocus) } - val firstSrc = value.src.firstOrNull() - if (firstSrc == null) { - runOnMainThreadSync { - player.setMediaItem(MediaItem.EMPTY) - player.prepare() - } - return - } - httpDataSourceFactory?.setDefaultRequestProperties(firstSrc.headers) + val src = value.src + httpDataSourceFactory?.setDefaultRequestProperties(src.headers) val currentItem = buildMediaItem( - firstSrc, + src, value.metadata, value.subtitles, value.castId, diff --git a/example/App.tsx b/example/App.tsx index 6fff3e0..a4a03c9 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -528,12 +528,10 @@ function App(): React.JSX.Element { const source = useMemo( () => ({ - src: [ - { - uri: PLAYLIST[currentIndex].uri, - headers: {}, - }, - ], + src: { + uri: PLAYLIST[currentIndex].uri, + headers: {}, + }, subtitles: [ { id: "kusu", diff --git a/nitrogen/generated/android/c++/JHybridOmniPlayerFactorySpec.cpp b/nitrogen/generated/android/c++/JHybridOmniPlayerFactorySpec.cpp index 16eac4c..914bcdf 100644 --- a/nitrogen/generated/android/c++/JHybridOmniPlayerFactorySpec.cpp +++ b/nitrogen/generated/android/c++/JHybridOmniPlayerFactorySpec.cpp @@ -33,11 +33,11 @@ namespace margelo::nitro::omni { struct CastOptions; } #include #include "JSource.hpp" #include "VideoSrc.hpp" -#include #include "JVideoSrc.hpp" #include #include #include "Subtitle.hpp" +#include #include "JSubtitle.hpp" #include "Metadata.hpp" #include "JMetadata.hpp" diff --git a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp index 1d755ac..398e2ef 100644 --- a/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp +++ b/nitrogen/generated/android/c++/JHybridOmniPlayerSpec.cpp @@ -35,11 +35,11 @@ namespace margelo::nitro::omni { enum class CastStatus; } #include "Source.hpp" #include "JSource.hpp" #include "VideoSrc.hpp" -#include #include "JVideoSrc.hpp" #include #include #include "Subtitle.hpp" +#include #include "JSubtitle.hpp" #include "Metadata.hpp" #include "JMetadata.hpp" diff --git a/nitrogen/generated/android/c++/JSource.hpp b/nitrogen/generated/android/c++/JSource.hpp index b1bdf1f..16399f0 100644 --- a/nitrogen/generated/android/c++/JSource.hpp +++ b/nitrogen/generated/android/c++/JSource.hpp @@ -42,8 +42,8 @@ namespace margelo::nitro::omni { [[nodiscard]] Source toCpp() const { static const auto clazz = javaClassStatic(); - static const auto fieldSrc = clazz->getField>("src"); - jni::local_ref> src = this->getFieldValue(fieldSrc); + static const auto fieldSrc = clazz->getField("src"); + jni::local_ref src = this->getFieldValue(fieldSrc); static const auto fieldStartTime = clazz->getField("startTime"); jni::local_ref startTime = this->getFieldValue(fieldStartTime); static const auto fieldSubtitles = clazz->getField>("subtitles"); @@ -59,16 +59,7 @@ namespace margelo::nitro::omni { static const auto fieldCastData = clazz->getField>("castData"); jni::local_ref> castData = this->getFieldValue(fieldCastData); return Source( - [&](auto&& __input) { - size_t __size = __input->size(); - std::vector __vector; - __vector.reserve(__size); - for (size_t __i = 0; __i < __size; __i++) { - auto __element = __input->getElement(__i); - __vector.push_back(__element->toCpp()); - } - return __vector; - }(src), + src->toCpp(), startTime != nullptr ? std::make_optional(startTime->value()) : std::nullopt, [&](auto&& __input) { size_t __size = __input->size(); @@ -110,21 +101,12 @@ namespace margelo::nitro::omni { */ [[maybe_unused]] static jni::local_ref fromCpp(const Source& value) { - using JSignature = JSource(jni::alias_ref>, jni::alias_ref, jni::alias_ref>, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>); + using JSignature = JSource(jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>); static const auto clazz = javaClassStatic(); static const auto create = clazz->getStaticMethod("fromCpp"); return create( clazz, - [&](auto&& __input) { - size_t __size = __input.size(); - jni::local_ref> __array = jni::JArrayClass::newArray(__size); - for (size_t __i = 0; __i < __size; __i++) { - const auto& __element = __input[__i]; - auto __elementJni = JVideoSrc::fromCpp(__element); - __array->setElement(__i, *__elementJni); - } - return __array; - }(value.src), + JVideoSrc::fromCpp(value.src), value.startTime.has_value() ? jni::JDouble::valueOf(value.startTime.value()) : nullptr, [&](auto&& __input) { size_t __size = __input.size(); diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Source.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Source.kt index 5581d28..d8531ce 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Source.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/omni/Source.kt @@ -20,7 +20,7 @@ import java.util.Objects data class Source( @DoNotStrip @Keep - val src: Array, + val src: VideoSrc, @DoNotStrip @Keep val startTime: Double?, @@ -79,7 +79,7 @@ data class Source( @Keep @Suppress("unused") @JvmStatic - private fun fromCpp(src: Array, startTime: Double?, subtitles: Array, fonts: Array?, metadata: Metadata?, mixAudio: MixAudioMode?, castId: String?, castData: Map?): Source { + private fun fromCpp(src: VideoSrc, startTime: Double?, subtitles: Array, fonts: Array?, metadata: Metadata?, mixAudio: MixAudioMode?, castId: String?, castData: Map?): Source { return Source(src, startTime, subtitles, fonts, metadata, mixAudio, castId, castData) } } diff --git a/nitrogen/generated/shared/c++/Source.hpp b/nitrogen/generated/shared/c++/Source.hpp index 00d43b1..8027b59 100644 --- a/nitrogen/generated/shared/c++/Source.hpp +++ b/nitrogen/generated/shared/c++/Source.hpp @@ -38,9 +38,9 @@ namespace margelo::nitro::omni { struct Metadata; } namespace margelo::nitro::omni { enum class MixAudioMode; } #include "VideoSrc.hpp" -#include #include #include "Subtitle.hpp" +#include #include #include "Metadata.hpp" #include "MixAudioMode.hpp" @@ -53,7 +53,7 @@ namespace margelo::nitro::omni { */ struct Source final { public: - std::vector src SWIFT_PRIVATE; + VideoSrc src SWIFT_PRIVATE; std::optional startTime SWIFT_PRIVATE; std::vector subtitles SWIFT_PRIVATE; std::optional> fonts SWIFT_PRIVATE; @@ -64,7 +64,7 @@ namespace margelo::nitro::omni { public: Source() = default; - explicit Source(std::vector src, std::optional startTime, std::vector subtitles, std::optional> fonts, std::optional metadata, std::optional mixAudio, std::optional castId, std::optional> castData): src(src), startTime(startTime), subtitles(subtitles), fonts(fonts), metadata(metadata), mixAudio(mixAudio), castId(castId), castData(castData) {} + explicit Source(VideoSrc src, std::optional startTime, std::vector subtitles, std::optional> fonts, std::optional metadata, std::optional mixAudio, std::optional castId, std::optional> castData): src(src), startTime(startTime), subtitles(subtitles), fonts(fonts), metadata(metadata), mixAudio(mixAudio), castId(castId), castData(castData) {} public: friend bool operator==(const Source& lhs, const Source& rhs) = default; @@ -80,7 +80,7 @@ namespace margelo::nitro { static inline margelo::nitro::omni::Source fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { jsi::Object obj = arg.asObject(runtime); return margelo::nitro::omni::Source( - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles"))), JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fonts"))), @@ -92,7 +92,7 @@ namespace margelo::nitro { } static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::Source& arg) { jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter>::toJSI(runtime, arg.src)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter::toJSI(runtime, arg.src)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "startTime"), JSIConverter>::toJSI(runtime, arg.startTime)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "subtitles"), JSIConverter>::toJSI(runtime, arg.subtitles)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "fonts"), JSIConverter>>::toJSI(runtime, arg.fonts)); @@ -110,7 +110,7 @@ namespace margelo::nitro { if (!nitro::isPlainObject(runtime, obj)) { return false; } - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles")))) return false; if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fonts")))) return false; diff --git a/src/provider.web.tsx b/src/provider.web.tsx index 2ed05d1..14f6f01 100644 --- a/src/provider.web.tsx +++ b/src/provider.web.tsx @@ -60,7 +60,7 @@ const PlayerInitializer = ({ useEffect(() => { player.source = source; - const uri = source?.src[0]?.uri; + const uri = source?.src?.uri; if (uri !== seekedForSrc.current) { seekedForSrc.current = uri; if (source?.startTime) store.seek(source.startTime); diff --git a/src/types/source.ts b/src/types/source.ts index da476d5..342072e 100644 --- a/src/types/source.ts +++ b/src/types/source.ts @@ -1,5 +1,5 @@ export interface Source { - src: VideoSrc[]; + src: VideoSrc; startTime?: number; subtitles: Subtitle[]; // fonts that can be used by ass subtitles on the web (native will use diff --git a/src/view.web.tsx b/src/view.web.tsx index e47a365..871a543 100644 --- a/src/view.web.tsx +++ b/src/view.web.tsx @@ -114,7 +114,7 @@ export const OmniView = ({ const containerRef = useRef(null); const ref = useRef(undefined!); - const src = player.source?.src[0]; + const src = player.source?.src; const isHls = src?.mimeType?.toLowerCase().includes("mpegurl") || src?.uri.split(/[?#]/)[0]?.toLowerCase().endsWith(".m3u8") ||