mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
Cleanup prev/next
This commit is contained in:
@@ -5,9 +5,12 @@ import androidx.media3.common.C
|
||||
import androidx.media3.common.C.TRACK_TYPE_AUDIO
|
||||
import androidx.media3.common.C.TRACK_TYPE_TEXT
|
||||
import androidx.media3.common.C.TRACK_TYPE_VIDEO
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.PlaybackParameters
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO
|
||||
import androidx.media3.common.Player.MEDIA_ITEM_TRANSITION_REASON_SEEK
|
||||
import androidx.media3.common.Player.STATE_BUFFERING
|
||||
import androidx.media3.common.Player.STATE_ENDED
|
||||
import androidx.media3.common.Player.STATE_IDLE
|
||||
@@ -34,6 +37,7 @@ class EventMap(private val player: Player) : HybridOmniEventMapSpec(), Player.Li
|
||||
private val stateBoolListeners = mutableMapOf<BoolProperty, MutableSet<(Boolean) -> Unit>>()
|
||||
private val playerStatusListeners = mutableSetOf<(PlayerStatus) -> Unit>()
|
||||
private var lastTimePosDispatchMs = 0L
|
||||
private var lastMediaItemIndex = 0
|
||||
|
||||
init {
|
||||
player.addListener(this)
|
||||
@@ -112,6 +116,20 @@ class EventMap(private val player: Player) : HybridOmniEventMapSpec(), Player.Li
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
||||
if (reason != MEDIA_ITEM_TRANSITION_REASON_AUTO && reason != MEDIA_ITEM_TRANSITION_REASON_SEEK) {
|
||||
lastMediaItemIndex = player.currentMediaItemIndex
|
||||
return
|
||||
}
|
||||
val newIndex = player.currentMediaItemIndex
|
||||
if (newIndex < lastMediaItemIndex) {
|
||||
onPrevListeners.forEach { it() }
|
||||
} else if (newIndex > lastMediaItemIndex) {
|
||||
onNextListeners.forEach { it() }
|
||||
}
|
||||
lastMediaItemIndex = newIndex
|
||||
}
|
||||
|
||||
override fun onPositionDiscontinuity(
|
||||
oldPosition: Player.PositionInfo,
|
||||
newPosition: Player.PositionInfo,
|
||||
|
||||
@@ -102,6 +102,7 @@ class MpvPlayer(ctx: Context) : BasePlayer(), MPVLib.EventObserver {
|
||||
private var currentTrackSelectionParameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT
|
||||
private var playerError: PlaybackException? = null
|
||||
private var playlistMetadata: MediaMetadata = MediaMetadata.EMPTY
|
||||
private var userInitiatedTransition: Boolean = false
|
||||
|
||||
private val availableCommands: Player.Commands = Player.Commands.Builder()
|
||||
.add(COMMAND_PLAY_PAUSE)
|
||||
@@ -185,6 +186,12 @@ class MpvPlayer(ctx: Context) : BasePlayer(), MPVLib.EventObserver {
|
||||
if (prev != currentMediaItemIndex) {
|
||||
events.add(EVENT_MEDIA_ITEM_TRANSITION)
|
||||
}
|
||||
val transitionReason = if (userInitiatedTransition) {
|
||||
MEDIA_ITEM_TRANSITION_REASON_SEEK
|
||||
} else {
|
||||
MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED
|
||||
}
|
||||
userInitiatedTransition = false
|
||||
notifyListeners(events.toTypedArray()) {
|
||||
it.onTimelineChanged(currentTimeline, TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED)
|
||||
it.onMediaMetadataChanged(mediaMetadata)
|
||||
@@ -192,7 +199,7 @@ class MpvPlayer(ctx: Context) : BasePlayer(), MPVLib.EventObserver {
|
||||
if (prev != currentMediaItemIndex) {
|
||||
it.onMediaItemTransition(
|
||||
currentMediaItem,
|
||||
MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED
|
||||
transitionReason
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -276,6 +283,7 @@ class MpvPlayer(ctx: Context) : BasePlayer(), MPVLib.EventObserver {
|
||||
if (targetIndex == INDEX_UNSET || targetIndex !in mediaItems.indices) return
|
||||
|
||||
if (targetIndex != currentMediaItemIndex) {
|
||||
userInitiatedTransition = true
|
||||
setMediaItems(mediaItems, targetIndex, positionMs)
|
||||
return
|
||||
}
|
||||
@@ -428,7 +436,7 @@ class MpvPlayer(ctx: Context) : BasePlayer(), MPVLib.EventObserver {
|
||||
0L,
|
||||
durationUs,
|
||||
0,
|
||||
0,
|
||||
mediaItems.size-1,
|
||||
0L
|
||||
)
|
||||
}
|
||||
|
||||
@@ -68,32 +68,32 @@ class OmniPlayer : HybridOmniPlayerSpec() {
|
||||
set(value) {
|
||||
Log.e("omni", "update source")
|
||||
currentSource = value
|
||||
val src = value.src.firstOrNull()
|
||||
if (src == null) {
|
||||
runOnMainThreadSync {
|
||||
player.setMediaItem(MediaItem.EMPTY)
|
||||
player.prepare()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val currentItem = buildMediaItem(src, value.metadata, value.subtitles)
|
||||
val mediaItems = mutableListOf<MediaItem>()
|
||||
|
||||
value.prev?.let { prevSource ->
|
||||
prevSource.src.firstOrNull()?.let { src ->
|
||||
mediaItems.add(buildMediaItem(src, prevSource.metadata, prevSource.subtitles))
|
||||
}
|
||||
if (value.metadata?.hasPrev == true) {
|
||||
mediaItems.add(currentItem)
|
||||
}
|
||||
|
||||
value.src.firstOrNull()?.let { src ->
|
||||
mediaItems.add(buildMediaItem(src, value.metadata, value.subtitles))
|
||||
}
|
||||
mediaItems.add(currentItem)
|
||||
|
||||
value.next?.let { nextSource ->
|
||||
nextSource.src.firstOrNull()?.let { src ->
|
||||
mediaItems.add(buildMediaItem(src, nextSource.metadata, nextSource.subtitles))
|
||||
}
|
||||
if (value.metadata?.hasNext == true) {
|
||||
mediaItems.add(currentItem)
|
||||
}
|
||||
|
||||
runOnMainThreadSync {
|
||||
if (mediaItems.isEmpty()) {
|
||||
player.setMediaItem(MediaItem.EMPTY)
|
||||
} else {
|
||||
val startIndex = if (value.prev != null) 1 else 0
|
||||
val startPositionMs = (value.startTime?.coerceAtLeast(0.0) ?: 0.0) * 1000.0
|
||||
player.setMediaItems(mediaItems, startIndex, startPositionMs.toLong())
|
||||
}
|
||||
val startIndex = if (value.metadata?.hasPrev == true) 1 else 0
|
||||
val startPositionMs = (value.startTime?.coerceAtLeast(0.0) ?: 0.0) * 1000.0
|
||||
player.setMediaItems(mediaItems, startIndex, startPositionMs.toLong())
|
||||
player.prepare()
|
||||
}
|
||||
}
|
||||
@@ -163,8 +163,8 @@ class OmniPlayer : HybridOmniPlayerSpec() {
|
||||
}
|
||||
}
|
||||
|
||||
override val hasPrev by mainThreadProperty { player.hasPreviousMediaItem() }
|
||||
override val hasNext by mainThreadProperty { player.hasNextMediaItem() }
|
||||
override val hasPrev: Boolean get() = currentSource?.metadata?.hasPrev == true
|
||||
override val hasNext: Boolean get() = currentSource?.metadata?.hasNext == true
|
||||
override val status by mainThreadProperty {
|
||||
when (player.playbackState) {
|
||||
Player.STATE_IDLE,
|
||||
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
///
|
||||
/// JBaseSource.hpp
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include "BaseSource.hpp"
|
||||
|
||||
#include "JMetadata.hpp"
|
||||
#include "JMixAudioMode.hpp"
|
||||
#include "JSubtitle.hpp"
|
||||
#include "JVideoSrc.hpp"
|
||||
#include "Metadata.hpp"
|
||||
#include "MixAudioMode.hpp"
|
||||
#include "Subtitle.hpp"
|
||||
#include "VideoSrc.hpp"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
/**
|
||||
* The C++ JNI bridge between the C++ struct "BaseSource" and the the Kotlin data class "BaseSource".
|
||||
*/
|
||||
struct JBaseSource final: public jni::JavaClass<JBaseSource> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/omni/BaseSource;";
|
||||
|
||||
public:
|
||||
/**
|
||||
* Convert this Java/Kotlin-based struct to the C++ struct BaseSource by copying all values to C++.
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
[[nodiscard]]
|
||||
BaseSource toCpp() const {
|
||||
static const auto clazz = javaClassStatic();
|
||||
static const auto fieldSrc = clazz->getField<jni::JArrayClass<JVideoSrc>>("src");
|
||||
jni::local_ref<jni::JArrayClass<JVideoSrc>> src = this->getFieldValue(fieldSrc);
|
||||
static const auto fieldStartTime = clazz->getField<jni::JDouble>("startTime");
|
||||
jni::local_ref<jni::JDouble> startTime = this->getFieldValue(fieldStartTime);
|
||||
static const auto fieldSubtitles = clazz->getField<jni::JArrayClass<JSubtitle>>("subtitles");
|
||||
jni::local_ref<jni::JArrayClass<JSubtitle>> subtitles = this->getFieldValue(fieldSubtitles);
|
||||
static const auto fieldMetadata = clazz->getField<JMetadata>("metadata");
|
||||
jni::local_ref<JMetadata> metadata = this->getFieldValue(fieldMetadata);
|
||||
static const auto fieldMixAudio = clazz->getField<JMixAudioMode>("mixAudio");
|
||||
jni::local_ref<JMixAudioMode> mixAudio = this->getFieldValue(fieldMixAudio);
|
||||
return BaseSource(
|
||||
[&]() {
|
||||
size_t __size = src->size();
|
||||
std::vector<VideoSrc> __vector;
|
||||
__vector.reserve(__size);
|
||||
for (size_t __i = 0; __i < __size; __i++) {
|
||||
auto __element = src->getElement(__i);
|
||||
__vector.push_back(__element->toCpp());
|
||||
}
|
||||
return __vector;
|
||||
}(),
|
||||
startTime != nullptr ? std::make_optional(startTime->value()) : std::nullopt,
|
||||
[&]() {
|
||||
size_t __size = subtitles->size();
|
||||
std::vector<Subtitle> __vector;
|
||||
__vector.reserve(__size);
|
||||
for (size_t __i = 0; __i < __size; __i++) {
|
||||
auto __element = subtitles->getElement(__i);
|
||||
__vector.push_back(__element->toCpp());
|
||||
}
|
||||
return __vector;
|
||||
}(),
|
||||
metadata != nullptr ? std::make_optional(metadata->toCpp()) : std::nullopt,
|
||||
mixAudio != nullptr ? std::make_optional(mixAudio->toCpp()) : std::nullopt
|
||||
);
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
static jni::local_ref<JBaseSource::javaobject> fromCpp(const BaseSource& value) {
|
||||
using JSignature = JBaseSource(jni::alias_ref<jni::JArrayClass<JVideoSrc>>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JArrayClass<JSubtitle>>, jni::alias_ref<JMetadata>, jni::alias_ref<JMixAudioMode>);
|
||||
static const auto clazz = javaClassStatic();
|
||||
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
||||
return create(
|
||||
clazz,
|
||||
[&]() {
|
||||
size_t __size = value.src.size();
|
||||
jni::local_ref<jni::JArrayClass<JVideoSrc>> __array = jni::JArrayClass<JVideoSrc>::newArray(__size);
|
||||
for (size_t __i = 0; __i < __size; __i++) {
|
||||
const auto& __element = value.src[__i];
|
||||
auto __elementJni = JVideoSrc::fromCpp(__element);
|
||||
__array->setElement(__i, *__elementJni);
|
||||
}
|
||||
return __array;
|
||||
}(),
|
||||
value.startTime.has_value() ? jni::JDouble::valueOf(value.startTime.value()) : nullptr,
|
||||
[&]() {
|
||||
size_t __size = value.subtitles.size();
|
||||
jni::local_ref<jni::JArrayClass<JSubtitle>> __array = jni::JArrayClass<JSubtitle>::newArray(__size);
|
||||
for (size_t __i = 0; __i < __size; __i++) {
|
||||
const auto& __element = value.subtitles[__i];
|
||||
auto __elementJni = JSubtitle::fromCpp(__element);
|
||||
__array->setElement(__i, *__elementJni);
|
||||
}
|
||||
return __array;
|
||||
}(),
|
||||
value.metadata.has_value() ? JMetadata::fromCpp(value.metadata.value()) : nullptr,
|
||||
value.mixAudio.has_value() ? JMixAudioMode::fromCpp(value.mixAudio.value()) : nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
@@ -11,8 +11,6 @@
|
||||
namespace margelo::nitro::omni { class HybridOmniPlayerSpec; }
|
||||
// Forward declaration of `Source` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Source; }
|
||||
// Forward declaration of `BaseSource` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct BaseSource; }
|
||||
// Forward declaration of `VideoSrc` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct VideoSrc; }
|
||||
// Forward declaration of `Subtitle` to properly resolve imports.
|
||||
@@ -27,13 +25,11 @@ namespace margelo::nitro::omni { enum class MixAudioMode; }
|
||||
#include "JHybridOmniPlayerSpec.hpp"
|
||||
#include "Source.hpp"
|
||||
#include "JSource.hpp"
|
||||
#include "BaseSource.hpp"
|
||||
#include <optional>
|
||||
#include "JBaseSource.hpp"
|
||||
#include "VideoSrc.hpp"
|
||||
#include <vector>
|
||||
#include "JVideoSrc.hpp"
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include "Subtitle.hpp"
|
||||
#include "JSubtitle.hpp"
|
||||
|
||||
+1
-5
@@ -11,8 +11,6 @@
|
||||
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
||||
// Forward declaration of `Source` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Source; }
|
||||
// Forward declaration of `BaseSource` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct BaseSource; }
|
||||
// Forward declaration of `VideoSrc` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct VideoSrc; }
|
||||
// Forward declaration of `Subtitle` to properly resolve imports.
|
||||
@@ -33,13 +31,11 @@ namespace margelo::nitro::omni { enum class PlayerStatus; }
|
||||
#include "JHybridOmniEventMapSpec.hpp"
|
||||
#include "Source.hpp"
|
||||
#include "JSource.hpp"
|
||||
#include "BaseSource.hpp"
|
||||
#include <optional>
|
||||
#include "JBaseSource.hpp"
|
||||
#include "VideoSrc.hpp"
|
||||
#include <vector>
|
||||
#include "JVideoSrc.hpp"
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include "Subtitle.hpp"
|
||||
#include "JSubtitle.hpp"
|
||||
|
||||
+11
-3
@@ -40,11 +40,17 @@ namespace margelo::nitro::omni {
|
||||
jni::local_ref<jni::JString> artist = this->getFieldValue(fieldArtist);
|
||||
static const auto fieldImageLink = clazz->getField<jni::JString>("imageLink");
|
||||
jni::local_ref<jni::JString> imageLink = this->getFieldValue(fieldImageLink);
|
||||
static const auto fieldHasPrev = clazz->getField<jni::JBoolean>("hasPrev");
|
||||
jni::local_ref<jni::JBoolean> hasPrev = this->getFieldValue(fieldHasPrev);
|
||||
static const auto fieldHasNext = clazz->getField<jni::JBoolean>("hasNext");
|
||||
jni::local_ref<jni::JBoolean> hasNext = this->getFieldValue(fieldHasNext);
|
||||
return Metadata(
|
||||
title->toStdString(),
|
||||
album != nullptr ? std::make_optional(album->toStdString()) : std::nullopt,
|
||||
artist != nullptr ? std::make_optional(artist->toStdString()) : std::nullopt,
|
||||
imageLink != nullptr ? std::make_optional(imageLink->toStdString()) : std::nullopt
|
||||
imageLink != nullptr ? std::make_optional(imageLink->toStdString()) : std::nullopt,
|
||||
hasPrev != nullptr ? std::make_optional(static_cast<bool>(hasPrev->value())) : std::nullopt,
|
||||
hasNext != nullptr ? std::make_optional(static_cast<bool>(hasNext->value())) : std::nullopt
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +60,7 @@ namespace margelo::nitro::omni {
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
static jni::local_ref<JMetadata::javaobject> fromCpp(const Metadata& value) {
|
||||
using JSignature = JMetadata(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
|
||||
using JSignature = JMetadata(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>);
|
||||
static const auto clazz = javaClassStatic();
|
||||
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
||||
return create(
|
||||
@@ -62,7 +68,9 @@ namespace margelo::nitro::omni {
|
||||
jni::make_jstring(value.title),
|
||||
value.album.has_value() ? jni::make_jstring(value.album.value()) : nullptr,
|
||||
value.artist.has_value() ? jni::make_jstring(value.artist.value()) : nullptr,
|
||||
value.imageLink.has_value() ? jni::make_jstring(value.imageLink.value()) : nullptr
|
||||
value.imageLink.has_value() ? jni::make_jstring(value.imageLink.value()) : nullptr,
|
||||
value.hasPrev.has_value() ? jni::JBoolean::valueOf(value.hasPrev.value()) : nullptr,
|
||||
value.hasNext.has_value() ? jni::JBoolean::valueOf(value.hasNext.value()) : nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-11
@@ -10,8 +10,6 @@
|
||||
#include <fbjni/fbjni.h>
|
||||
#include "Source.hpp"
|
||||
|
||||
#include "BaseSource.hpp"
|
||||
#include "JBaseSource.hpp"
|
||||
#include "JMetadata.hpp"
|
||||
#include "JMixAudioMode.hpp"
|
||||
#include "JSubtitle.hpp"
|
||||
@@ -44,10 +42,6 @@ namespace margelo::nitro::omni {
|
||||
[[nodiscard]]
|
||||
Source toCpp() const {
|
||||
static const auto clazz = javaClassStatic();
|
||||
static const auto fieldPrev = clazz->getField<JBaseSource>("prev");
|
||||
jni::local_ref<JBaseSource> prev = this->getFieldValue(fieldPrev);
|
||||
static const auto fieldNext = clazz->getField<JBaseSource>("next");
|
||||
jni::local_ref<JBaseSource> next = this->getFieldValue(fieldNext);
|
||||
static const auto fieldSrc = clazz->getField<jni::JArrayClass<JVideoSrc>>("src");
|
||||
jni::local_ref<jni::JArrayClass<JVideoSrc>> src = this->getFieldValue(fieldSrc);
|
||||
static const auto fieldStartTime = clazz->getField<jni::JDouble>("startTime");
|
||||
@@ -59,8 +53,6 @@ namespace margelo::nitro::omni {
|
||||
static const auto fieldMixAudio = clazz->getField<JMixAudioMode>("mixAudio");
|
||||
jni::local_ref<JMixAudioMode> mixAudio = this->getFieldValue(fieldMixAudio);
|
||||
return Source(
|
||||
prev != nullptr ? std::make_optional(prev->toCpp()) : std::nullopt,
|
||||
next != nullptr ? std::make_optional(next->toCpp()) : std::nullopt,
|
||||
[&]() {
|
||||
size_t __size = src->size();
|
||||
std::vector<VideoSrc> __vector;
|
||||
@@ -93,13 +85,11 @@ namespace margelo::nitro::omni {
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
static jni::local_ref<JSource::javaobject> fromCpp(const Source& value) {
|
||||
using JSignature = JSource(jni::alias_ref<JBaseSource>, jni::alias_ref<JBaseSource>, jni::alias_ref<jni::JArrayClass<JVideoSrc>>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JArrayClass<JSubtitle>>, jni::alias_ref<JMetadata>, jni::alias_ref<JMixAudioMode>);
|
||||
using JSignature = JSource(jni::alias_ref<jni::JArrayClass<JVideoSrc>>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JArrayClass<JSubtitle>>, jni::alias_ref<JMetadata>, jni::alias_ref<JMixAudioMode>);
|
||||
static const auto clazz = javaClassStatic();
|
||||
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
||||
return create(
|
||||
clazz,
|
||||
value.prev.has_value() ? JBaseSource::fromCpp(value.prev.value()) : nullptr,
|
||||
value.next.has_value() ? JBaseSource::fromCpp(value.next.value()) : nullptr,
|
||||
[&]() {
|
||||
size_t __size = value.src.size();
|
||||
jni::local_ref<jni::JArrayClass<JVideoSrc>> __array = jni::JArrayClass<JVideoSrc>::newArray(__size);
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
///
|
||||
/// BaseSource.kt
|
||||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
||||
/// https://github.com/mrousavy/nitro
|
||||
/// Copyright © Marc Rousavy @ Margelo
|
||||
///
|
||||
|
||||
package com.margelo.nitro.omni
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.facebook.proguard.annotations.DoNotStrip
|
||||
|
||||
|
||||
/**
|
||||
* Represents the JavaScript object/struct "BaseSource".
|
||||
*/
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
data class BaseSource(
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val src: Array<VideoSrc>,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val startTime: Double?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val subtitles: Array<Subtitle>,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val metadata: Metadata?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val mixAudio: MixAudioMode?
|
||||
) {
|
||||
/* primary constructor */
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Constructor called from C++
|
||||
*/
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
@JvmStatic
|
||||
private fun fromCpp(src: Array<VideoSrc>, startTime: Double?, subtitles: Array<Subtitle>, metadata: Metadata?, mixAudio: MixAudioMode?): BaseSource {
|
||||
return BaseSource(src, startTime, subtitles, metadata, mixAudio)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,13 @@ data class Metadata(
|
||||
val artist: String?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val imageLink: String?
|
||||
val imageLink: String?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val hasPrev: Boolean?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val hasNext: Boolean?
|
||||
) {
|
||||
/* primary constructor */
|
||||
|
||||
@@ -40,8 +46,8 @@ data class Metadata(
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
@JvmStatic
|
||||
private fun fromCpp(title: String, album: String?, artist: String?, imageLink: String?): Metadata {
|
||||
return Metadata(title, album, artist, imageLink)
|
||||
private fun fromCpp(title: String, album: String?, artist: String?, imageLink: String?, hasPrev: Boolean?, hasNext: Boolean?): Metadata {
|
||||
return Metadata(title, album, artist, imageLink, hasPrev, hasNext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,6 @@ import com.facebook.proguard.annotations.DoNotStrip
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
data class Source(
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val prev: BaseSource?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val next: BaseSource?,
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
val src: Array<VideoSrc>,
|
||||
@@ -49,8 +43,8 @@ data class Source(
|
||||
@Keep
|
||||
@Suppress("unused")
|
||||
@JvmStatic
|
||||
private fun fromCpp(prev: BaseSource?, next: BaseSource?, src: Array<VideoSrc>, startTime: Double?, subtitles: Array<Subtitle>, metadata: Metadata?, mixAudio: MixAudioMode?): Source {
|
||||
return Source(prev, next, src, startTime, subtitles, metadata, mixAudio)
|
||||
private fun fromCpp(src: Array<VideoSrc>, startTime: Double?, subtitles: Array<Subtitle>, metadata: Metadata?, mixAudio: MixAudioMode?): Source {
|
||||
return Source(src, startTime, subtitles, metadata, mixAudio)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
///
|
||||
/// BaseSource.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(<NitroModules/JSIConverter.hpp>)
|
||||
#include <NitroModules/JSIConverter.hpp>
|
||||
#else
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
||||
#include <NitroModules/NitroDefines.hpp>
|
||||
#else
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
||||
#include <NitroModules/JSIHelpers.hpp>
|
||||
#else
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
||||
#include <NitroModules/PropNameIDCache.hpp>
|
||||
#else
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
|
||||
// Forward declaration of `VideoSrc` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct VideoSrc; }
|
||||
// Forward declaration of `Subtitle` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Subtitle; }
|
||||
// Forward declaration of `Metadata` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct Metadata; }
|
||||
// Forward declaration of `MixAudioMode` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { enum class MixAudioMode; }
|
||||
|
||||
#include "VideoSrc.hpp"
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "Subtitle.hpp"
|
||||
#include "Metadata.hpp"
|
||||
#include "MixAudioMode.hpp"
|
||||
|
||||
namespace margelo::nitro::omni {
|
||||
|
||||
/**
|
||||
* A struct which can be represented as a JavaScript object (BaseSource).
|
||||
*/
|
||||
struct BaseSource final {
|
||||
public:
|
||||
std::vector<VideoSrc> src SWIFT_PRIVATE;
|
||||
std::optional<double> startTime SWIFT_PRIVATE;
|
||||
std::vector<Subtitle> subtitles SWIFT_PRIVATE;
|
||||
std::optional<Metadata> metadata SWIFT_PRIVATE;
|
||||
std::optional<MixAudioMode> mixAudio SWIFT_PRIVATE;
|
||||
|
||||
public:
|
||||
BaseSource() = default;
|
||||
explicit BaseSource(std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio): src(src), startTime(startTime), subtitles(subtitles), metadata(metadata), mixAudio(mixAudio) {}
|
||||
|
||||
public:
|
||||
friend bool operator==(const BaseSource& lhs, const BaseSource& rhs) = default;
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro::omni
|
||||
|
||||
namespace margelo::nitro {
|
||||
|
||||
// C++ BaseSource <> JS BaseSource (object)
|
||||
template <>
|
||||
struct JSIConverter<margelo::nitro::omni::BaseSource> final {
|
||||
static inline margelo::nitro::omni::BaseSource fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
||||
jsi::Object obj = arg.asObject(runtime);
|
||||
return margelo::nitro::omni::BaseSource(
|
||||
JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))),
|
||||
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime"))),
|
||||
JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles"))),
|
||||
JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata"))),
|
||||
JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))
|
||||
);
|
||||
}
|
||||
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::BaseSource& arg) {
|
||||
jsi::Object obj(runtime);
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::toJSI(runtime, arg.src));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startTime"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.startTime));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "subtitles"), JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::toJSI(runtime, arg.subtitles));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "metadata"), JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::toJSI(runtime, arg.metadata));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mixAudio"), JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::toJSI(runtime, arg.mixAudio));
|
||||
return obj;
|
||||
}
|
||||
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
||||
if (!value.isObject()) {
|
||||
return false;
|
||||
}
|
||||
jsi::Object obj = value.getObject(runtime);
|
||||
if (!nitro::isPlainObject(runtime, obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false;
|
||||
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime")))) return false;
|
||||
if (!JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles")))) return false;
|
||||
if (!JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata")))) return false;
|
||||
if (!JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace margelo::nitro
|
||||
+10
-2
@@ -44,10 +44,12 @@ namespace margelo::nitro::omni {
|
||||
std::optional<std::string> album SWIFT_PRIVATE;
|
||||
std::optional<std::string> artist SWIFT_PRIVATE;
|
||||
std::optional<std::string> imageLink SWIFT_PRIVATE;
|
||||
std::optional<bool> hasPrev SWIFT_PRIVATE;
|
||||
std::optional<bool> hasNext SWIFT_PRIVATE;
|
||||
|
||||
public:
|
||||
Metadata() = default;
|
||||
explicit Metadata(std::string title, std::optional<std::string> album, std::optional<std::string> artist, std::optional<std::string> imageLink): title(title), album(album), artist(artist), imageLink(imageLink) {}
|
||||
explicit Metadata(std::string title, std::optional<std::string> album, std::optional<std::string> artist, std::optional<std::string> imageLink, std::optional<bool> hasPrev, std::optional<bool> hasNext): title(title), album(album), artist(artist), imageLink(imageLink), hasPrev(hasPrev), hasNext(hasNext) {}
|
||||
|
||||
public:
|
||||
friend bool operator==(const Metadata& lhs, const Metadata& rhs) = default;
|
||||
@@ -66,7 +68,9 @@ namespace margelo::nitro {
|
||||
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "title"))),
|
||||
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "album"))),
|
||||
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "artist"))),
|
||||
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "imageLink")))
|
||||
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "imageLink"))),
|
||||
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasPrev"))),
|
||||
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasNext")))
|
||||
);
|
||||
}
|
||||
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::Metadata& arg) {
|
||||
@@ -75,6 +79,8 @@ namespace margelo::nitro {
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "album"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.album));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "artist"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.artist));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "imageLink"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.imageLink));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "hasPrev"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.hasPrev));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "hasNext"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.hasNext));
|
||||
return obj;
|
||||
}
|
||||
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
||||
@@ -89,6 +95,8 @@ namespace margelo::nitro {
|
||||
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "album")))) return false;
|
||||
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "artist")))) return false;
|
||||
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "imageLink")))) return false;
|
||||
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasPrev")))) return false;
|
||||
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasNext")))) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Generated
+2
-13
@@ -28,8 +28,6 @@
|
||||
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
||||
#endif
|
||||
|
||||
// Forward declaration of `BaseSource` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct BaseSource; }
|
||||
// Forward declaration of `VideoSrc` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { struct VideoSrc; }
|
||||
// Forward declaration of `Subtitle` to properly resolve imports.
|
||||
@@ -39,10 +37,9 @@ namespace margelo::nitro::omni { struct Metadata; }
|
||||
// Forward declaration of `MixAudioMode` to properly resolve imports.
|
||||
namespace margelo::nitro::omni { enum class MixAudioMode; }
|
||||
|
||||
#include "BaseSource.hpp"
|
||||
#include <optional>
|
||||
#include "VideoSrc.hpp"
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "Subtitle.hpp"
|
||||
#include "Metadata.hpp"
|
||||
#include "MixAudioMode.hpp"
|
||||
@@ -54,8 +51,6 @@ namespace margelo::nitro::omni {
|
||||
*/
|
||||
struct Source final {
|
||||
public:
|
||||
std::optional<BaseSource> prev SWIFT_PRIVATE;
|
||||
std::optional<BaseSource> next SWIFT_PRIVATE;
|
||||
std::vector<VideoSrc> src SWIFT_PRIVATE;
|
||||
std::optional<double> startTime SWIFT_PRIVATE;
|
||||
std::vector<Subtitle> subtitles SWIFT_PRIVATE;
|
||||
@@ -64,7 +59,7 @@ namespace margelo::nitro::omni {
|
||||
|
||||
public:
|
||||
Source() = default;
|
||||
explicit Source(std::optional<BaseSource> prev, std::optional<BaseSource> next, std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio): prev(prev), next(next), src(src), startTime(startTime), subtitles(subtitles), metadata(metadata), mixAudio(mixAudio) {}
|
||||
explicit Source(std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio): src(src), startTime(startTime), subtitles(subtitles), metadata(metadata), mixAudio(mixAudio) {}
|
||||
|
||||
public:
|
||||
friend bool operator==(const Source& lhs, const Source& rhs) = default;
|
||||
@@ -80,8 +75,6 @@ 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<std::optional<margelo::nitro::omni::BaseSource>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prev"))),
|
||||
JSIConverter<std::optional<margelo::nitro::omni::BaseSource>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "next"))),
|
||||
JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))),
|
||||
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime"))),
|
||||
JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles"))),
|
||||
@@ -91,8 +84,6 @@ 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, "prev"), JSIConverter<std::optional<margelo::nitro::omni::BaseSource>>::toJSI(runtime, arg.prev));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "next"), JSIConverter<std::optional<margelo::nitro::omni::BaseSource>>::toJSI(runtime, arg.next));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::toJSI(runtime, arg.src));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startTime"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.startTime));
|
||||
obj.setProperty(runtime, PropNameIDCache::get(runtime, "subtitles"), JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::toJSI(runtime, arg.subtitles));
|
||||
@@ -108,8 +99,6 @@ namespace margelo::nitro {
|
||||
if (!nitro::isPlainObject(runtime, obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!JSIConverter<std::optional<margelo::nitro::omni::BaseSource>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prev")))) return false;
|
||||
if (!JSIConverter<std::optional<margelo::nitro::omni::BaseSource>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "next")))) return false;
|
||||
if (!JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false;
|
||||
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime")))) return false;
|
||||
if (!JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles")))) return false;
|
||||
|
||||
+3
-6
@@ -1,4 +1,4 @@
|
||||
export interface BaseSource {
|
||||
export interface Source {
|
||||
src: VideoSrc[];
|
||||
startTime?: number;
|
||||
subtitles: Subtitle[];
|
||||
@@ -6,11 +6,6 @@ export interface BaseSource {
|
||||
mixAudio?: MixAudioMode;
|
||||
}
|
||||
|
||||
export interface Source extends BaseSource {
|
||||
prev?: BaseSource
|
||||
next?: BaseSource
|
||||
}
|
||||
|
||||
export interface VideoSrc {
|
||||
uri: string;
|
||||
mimeType?: string;
|
||||
@@ -32,6 +27,8 @@ export interface Metadata {
|
||||
album?: string;
|
||||
artist?: string;
|
||||
imageLink?: string;
|
||||
hasPrev?: boolean;
|
||||
hasNext?: boolean;
|
||||
}
|
||||
|
||||
export type MixAudioMode = "mixWithOthers" | "doNotMix" | "duckOthers" | "auto";
|
||||
|
||||
Reference in New Issue
Block a user