mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecc8f08ffa |
@@ -177,49 +177,52 @@ class OmniPlayer : HybridOmniPlayerSpec() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setSource(src: Source?) {
|
override var source: Source? = null
|
||||||
if (src == null) {
|
set(value) {
|
||||||
|
field = value
|
||||||
|
if (value == null) {
|
||||||
|
runOnMainThreadSync {
|
||||||
|
player.setMediaItem(MediaItem.EMPTY)
|
||||||
|
player.prepare()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val handleAudioFocus =
|
||||||
|
(value.mixAudio ?: MixAudioMode.AUTO) != MixAudioMode.MIXWITHOTHERS
|
||||||
|
val audioAttributes = AudioAttributes.Builder()
|
||||||
|
.setUsage(C.USAGE_MEDIA)
|
||||||
|
.setContentType(C.AUDIO_CONTENT_TYPE_MOVIE)
|
||||||
|
.build()
|
||||||
|
runOnMainThread { player.setAudioAttributes(audioAttributes, handleAudioFocus) }
|
||||||
|
val firstSrc = value.src.firstOrNull()
|
||||||
|
if (firstSrc == null) {
|
||||||
|
runOnMainThreadSync {
|
||||||
|
player.setMediaItem(MediaItem.EMPTY)
|
||||||
|
player.prepare()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val currentItem = buildMediaItem(firstSrc, value.metadata, value.subtitles)
|
||||||
|
val mediaItems = mutableListOf<MediaItem>()
|
||||||
|
|
||||||
|
if (value.metadata?.hasPrev == true) {
|
||||||
|
mediaItems.add(currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaItems.add(currentItem)
|
||||||
|
|
||||||
|
if (value.metadata?.hasNext == true) {
|
||||||
|
mediaItems.add(currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
runOnMainThreadSync {
|
runOnMainThreadSync {
|
||||||
player.setMediaItem(MediaItem.EMPTY)
|
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()
|
player.prepare()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
val handleAudioFocus = (src.mixAudio ?: MixAudioMode.AUTO) != MixAudioMode.MIXWITHOTHERS
|
|
||||||
val audioAttributes = AudioAttributes.Builder()
|
|
||||||
.setUsage(C.USAGE_MEDIA)
|
|
||||||
.setContentType(C.AUDIO_CONTENT_TYPE_MOVIE)
|
|
||||||
.build()
|
|
||||||
runOnMainThread { player.setAudioAttributes(audioAttributes, handleAudioFocus) }
|
|
||||||
val source = src.src.firstOrNull()
|
|
||||||
if (source == null) {
|
|
||||||
runOnMainThreadSync {
|
|
||||||
player.setMediaItem(MediaItem.EMPTY)
|
|
||||||
player.prepare()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val currentItem = buildMediaItem(source, src.metadata, src.subtitles)
|
|
||||||
val mediaItems = mutableListOf<MediaItem>()
|
|
||||||
|
|
||||||
if (src.metadata?.hasPrev == true) {
|
|
||||||
mediaItems.add(currentItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaItems.add(currentItem)
|
|
||||||
|
|
||||||
if (src.metadata?.hasNext == true) {
|
|
||||||
mediaItems.add(currentItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
runOnMainThreadSync {
|
|
||||||
val startIndex = if (src.metadata?.hasPrev == true) 1 else 0
|
|
||||||
val startPositionMs = (src.startTime?.coerceAtLeast(0.0) ?: 0.0) * 1000.0
|
|
||||||
player.setMediaItems(mediaItems, startIndex, startPositionMs.toLong())
|
|
||||||
player.prepare()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun play() {
|
override fun play() {
|
||||||
runOnMainThreadSync { player.play() }
|
runOnMainThreadSync { player.play() }
|
||||||
@@ -312,6 +315,7 @@ class OmniPlayer : HybridOmniPlayerSpec() {
|
|||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> (0 until group.length).firstOrNull { group.isTrackSelected(it) }
|
else -> (0 until group.length).firstOrNull { group.isTrackSelected(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +351,12 @@ class OmniPlayer : HybridOmniPlayerSpec() {
|
|||||||
|
|
||||||
player.trackSelectionParameters = player.trackSelectionParameters
|
player.trackSelectionParameters = player.trackSelectionParameters
|
||||||
.buildUpon()
|
.buildUpon()
|
||||||
.setOverrideForType(TrackSelectionOverride(group.mediaTrackGroup, rendition.id.toInt()))
|
.setOverrideForType(
|
||||||
|
TrackSelectionOverride(
|
||||||
|
group.mediaTrackGroup,
|
||||||
|
rendition.id.toInt()
|
||||||
|
)
|
||||||
|
)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,7 +392,8 @@ class OmniPlayerService : MediaSessionService() {
|
|||||||
.build()
|
.build()
|
||||||
|
|
||||||
setMediaNotificationProvider(DefaultMediaNotificationProvider.Builder(this).build().apply {
|
setMediaNotificationProvider(DefaultMediaNotificationProvider.Builder(this).build().apply {
|
||||||
setSmallIcon(applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_media_play)
|
setSmallIcon(applicationInfo.icon.takeIf { it != 0 }
|
||||||
|
?: android.R.drawable.ic_media_play)
|
||||||
})
|
})
|
||||||
addSession(mediaSession)
|
addSession(mediaSession)
|
||||||
setShowNotificationForIdlePlayer(SHOW_NOTIFICATION_FOR_IDLE_PLAYER_ALWAYS)
|
setShowNotificationForIdlePlayer(SHOW_NOTIFICATION_FOR_IDLE_PLAYER_ALWAYS)
|
||||||
@@ -415,7 +425,8 @@ class OmniPlayerService : MediaSessionService() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return NotificationCompat.Builder(this, "omni_playback")
|
return NotificationCompat.Builder(this, "omni_playback")
|
||||||
.setSmallIcon(applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_media_play)
|
.setSmallIcon(applicationInfo.icon.takeIf { it != 0 }
|
||||||
|
?: android.R.drawable.ic_media_play)
|
||||||
.setContentTitle("Omni Player")
|
.setContentTitle("Omni Player")
|
||||||
.setContentText("Preparing playback...")
|
.setContentText("Preparing playback...")
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.margelo.nitro.omni.Source
|
|||||||
class OmniPlayerFactory(val context: ThemedReactContext) : HybridOmniPlayerFactorySpec() {
|
class OmniPlayerFactory(val context: ThemedReactContext) : HybridOmniPlayerFactorySpec() {
|
||||||
override fun createPlayer(props: Source?): HybridOmniPlayerSpec {
|
override fun createPlayer(props: Source?): HybridOmniPlayerSpec {
|
||||||
return OmniPlayer().apply {
|
return OmniPlayer().apply {
|
||||||
setSource(props)
|
source = props
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-22
@@ -9,14 +9,6 @@
|
|||||||
|
|
||||||
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
||||||
// 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; }
|
|
||||||
// Forward declaration of `CastStatus` to properly resolve imports.
|
|
||||||
namespace margelo::nitro::omni { enum class CastStatus; }
|
|
||||||
// Forward declaration of `Source` to properly resolve imports.
|
// Forward declaration of `Source` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { struct Source; }
|
namespace margelo::nitro::omni { struct Source; }
|
||||||
// Forward declaration of `VideoSrc` to properly resolve imports.
|
// Forward declaration of `VideoSrc` to properly resolve imports.
|
||||||
@@ -27,25 +19,25 @@ namespace margelo::nitro::omni { struct Subtitle; }
|
|||||||
namespace margelo::nitro::omni { struct Metadata; }
|
namespace margelo::nitro::omni { struct Metadata; }
|
||||||
// Forward declaration of `MixAudioMode` to properly resolve imports.
|
// Forward declaration of `MixAudioMode` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { enum class MixAudioMode; }
|
namespace margelo::nitro::omni { enum class MixAudioMode; }
|
||||||
|
// 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; }
|
||||||
|
// Forward declaration of `CastStatus` to properly resolve imports.
|
||||||
|
namespace margelo::nitro::omni { enum class CastStatus; }
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "HybridOmniEventMapSpec.hpp"
|
#include "HybridOmniEventMapSpec.hpp"
|
||||||
#include "JHybridOmniEventMapSpec.hpp"
|
#include "JHybridOmniEventMapSpec.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include "Track.hpp"
|
|
||||||
#include <vector>
|
|
||||||
#include "JTrack.hpp"
|
|
||||||
#include <string>
|
|
||||||
#include "Rendition.hpp"
|
|
||||||
#include "JRendition.hpp"
|
|
||||||
#include "PlayerStatus.hpp"
|
|
||||||
#include "JPlayerStatus.hpp"
|
|
||||||
#include "CastStatus.hpp"
|
|
||||||
#include "JCastStatus.hpp"
|
|
||||||
#include "Source.hpp"
|
#include "Source.hpp"
|
||||||
#include "JSource.hpp"
|
#include "JSource.hpp"
|
||||||
#include "VideoSrc.hpp"
|
#include "VideoSrc.hpp"
|
||||||
|
#include <vector>
|
||||||
#include "JVideoSrc.hpp"
|
#include "JVideoSrc.hpp"
|
||||||
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "Subtitle.hpp"
|
#include "Subtitle.hpp"
|
||||||
#include "JSubtitle.hpp"
|
#include "JSubtitle.hpp"
|
||||||
@@ -53,6 +45,14 @@ namespace margelo::nitro::omni { enum class MixAudioMode; }
|
|||||||
#include "JMetadata.hpp"
|
#include "JMetadata.hpp"
|
||||||
#include "MixAudioMode.hpp"
|
#include "MixAudioMode.hpp"
|
||||||
#include "JMixAudioMode.hpp"
|
#include "JMixAudioMode.hpp"
|
||||||
|
#include "Track.hpp"
|
||||||
|
#include "JTrack.hpp"
|
||||||
|
#include "Rendition.hpp"
|
||||||
|
#include "JRendition.hpp"
|
||||||
|
#include "PlayerStatus.hpp"
|
||||||
|
#include "JPlayerStatus.hpp"
|
||||||
|
#include "CastStatus.hpp"
|
||||||
|
#include "JCastStatus.hpp"
|
||||||
|
|
||||||
namespace margelo::nitro::omni {
|
namespace margelo::nitro::omni {
|
||||||
|
|
||||||
@@ -98,6 +98,15 @@ namespace margelo::nitro::omni {
|
|||||||
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JBoolean> /* showNotification */)>("setShowNotification");
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JBoolean> /* showNotification */)>("setShowNotification");
|
||||||
method(_javaPart, showNotification.has_value() ? jni::JBoolean::valueOf(showNotification.value()) : nullptr);
|
method(_javaPart, showNotification.has_value() ? jni::JBoolean::valueOf(showNotification.value()) : nullptr);
|
||||||
}
|
}
|
||||||
|
std::optional<Source> JHybridOmniPlayerSpec::getSource() {
|
||||||
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JSource>()>("getSource");
|
||||||
|
auto __result = method(_javaPart);
|
||||||
|
return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
|
||||||
|
}
|
||||||
|
void JHybridOmniPlayerSpec::setSource(const std::optional<Source>& source) {
|
||||||
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSource> /* source */)>("setSource");
|
||||||
|
method(_javaPart, source.has_value() ? JSource::fromCpp(source.value()) : nullptr);
|
||||||
|
}
|
||||||
bool JHybridOmniPlayerSpec::getHasPrev() {
|
bool JHybridOmniPlayerSpec::getHasPrev() {
|
||||||
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getHasPrev");
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("getHasPrev");
|
||||||
auto __result = method(_javaPart);
|
auto __result = method(_javaPart);
|
||||||
@@ -232,10 +241,6 @@ namespace margelo::nitro::omni {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
void JHybridOmniPlayerSpec::setSource(const std::optional<Source>& source) {
|
|
||||||
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSource> /* source */)>("setSource");
|
|
||||||
method(_javaPart, source.has_value() ? JSource::fromCpp(source.value()) : nullptr);
|
|
||||||
}
|
|
||||||
void JHybridOmniPlayerSpec::play() {
|
void JHybridOmniPlayerSpec::play() {
|
||||||
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("play");
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("play");
|
||||||
method(_javaPart);
|
method(_javaPart);
|
||||||
|
|||||||
+2
-1
@@ -53,6 +53,8 @@ namespace margelo::nitro::omni {
|
|||||||
std::shared_ptr<HybridOmniEventMapSpec> getEventMap() override;
|
std::shared_ptr<HybridOmniEventMapSpec> getEventMap() override;
|
||||||
std::optional<bool> getShowNotification() override;
|
std::optional<bool> getShowNotification() override;
|
||||||
void setShowNotification(std::optional<bool> showNotification) override;
|
void setShowNotification(std::optional<bool> showNotification) override;
|
||||||
|
std::optional<Source> getSource() override;
|
||||||
|
void setSource(const std::optional<Source>& source) override;
|
||||||
bool getHasPrev() override;
|
bool getHasPrev() override;
|
||||||
bool getHasNext() override;
|
bool getHasNext() override;
|
||||||
std::vector<Track> getVideos() override;
|
std::vector<Track> getVideos() override;
|
||||||
@@ -76,7 +78,6 @@ namespace margelo::nitro::omni {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Methods
|
// Methods
|
||||||
void setSource(const std::optional<Source>& source) override;
|
|
||||||
void play() override;
|
void play() override;
|
||||||
void pause() override;
|
void pause() override;
|
||||||
void seekBy(double offset) override;
|
void seekBy(double offset) override;
|
||||||
|
|||||||
+6
-4
@@ -35,6 +35,12 @@ abstract class HybridOmniPlayerSpec: HybridObject() {
|
|||||||
@set:Keep
|
@set:Keep
|
||||||
abstract var showNotification: Boolean?
|
abstract var showNotification: Boolean?
|
||||||
|
|
||||||
|
@get:DoNotStrip
|
||||||
|
@get:Keep
|
||||||
|
@set:DoNotStrip
|
||||||
|
@set:Keep
|
||||||
|
abstract var source: Source?
|
||||||
|
|
||||||
@get:DoNotStrip
|
@get:DoNotStrip
|
||||||
@get:Keep
|
@get:Keep
|
||||||
abstract val hasPrev: Boolean
|
abstract val hasPrev: Boolean
|
||||||
@@ -108,10 +114,6 @@ abstract class HybridOmniPlayerSpec: HybridObject() {
|
|||||||
abstract val castStatus: CastStatus
|
abstract val castStatus: CastStatus
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
@DoNotStrip
|
|
||||||
@Keep
|
|
||||||
abstract fun setSource(source: Source?): Unit
|
|
||||||
|
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
@Keep
|
@Keep
|
||||||
abstract fun play(): Unit
|
abstract fun play(): Unit
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,8 @@ namespace margelo::nitro::omni {
|
|||||||
prototype.registerHybridGetter("eventMap", &HybridOmniPlayerSpec::getEventMap);
|
prototype.registerHybridGetter("eventMap", &HybridOmniPlayerSpec::getEventMap);
|
||||||
prototype.registerHybridGetter("showNotification", &HybridOmniPlayerSpec::getShowNotification);
|
prototype.registerHybridGetter("showNotification", &HybridOmniPlayerSpec::getShowNotification);
|
||||||
prototype.registerHybridSetter("showNotification", &HybridOmniPlayerSpec::setShowNotification);
|
prototype.registerHybridSetter("showNotification", &HybridOmniPlayerSpec::setShowNotification);
|
||||||
|
prototype.registerHybridGetter("source", &HybridOmniPlayerSpec::getSource);
|
||||||
|
prototype.registerHybridSetter("source", &HybridOmniPlayerSpec::setSource);
|
||||||
prototype.registerHybridGetter("hasPrev", &HybridOmniPlayerSpec::getHasPrev);
|
prototype.registerHybridGetter("hasPrev", &HybridOmniPlayerSpec::getHasPrev);
|
||||||
prototype.registerHybridGetter("hasNext", &HybridOmniPlayerSpec::getHasNext);
|
prototype.registerHybridGetter("hasNext", &HybridOmniPlayerSpec::getHasNext);
|
||||||
prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos);
|
prototype.registerHybridGetter("videos", &HybridOmniPlayerSpec::getVideos);
|
||||||
@@ -37,7 +39,6 @@ namespace margelo::nitro::omni {
|
|||||||
prototype.registerHybridSetter("muted", &HybridOmniPlayerSpec::setMuted);
|
prototype.registerHybridSetter("muted", &HybridOmniPlayerSpec::setMuted);
|
||||||
prototype.registerHybridGetter("isAutoQuality", &HybridOmniPlayerSpec::getIsAutoQuality);
|
prototype.registerHybridGetter("isAutoQuality", &HybridOmniPlayerSpec::getIsAutoQuality);
|
||||||
prototype.registerHybridGetter("castStatus", &HybridOmniPlayerSpec::getCastStatus);
|
prototype.registerHybridGetter("castStatus", &HybridOmniPlayerSpec::getCastStatus);
|
||||||
prototype.registerHybridMethod("setSource", &HybridOmniPlayerSpec::setSource);
|
|
||||||
prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play);
|
prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play);
|
||||||
prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause);
|
prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause);
|
||||||
prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy);
|
prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy);
|
||||||
|
|||||||
+5
-4
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
// Forward declaration of `HybridOmniEventMapSpec` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
namespace margelo::nitro::omni { class HybridOmniEventMapSpec; }
|
||||||
|
// Forward declaration of `Source` to properly resolve imports.
|
||||||
|
namespace margelo::nitro::omni { struct Source; }
|
||||||
// Forward declaration of `Track` to properly resolve imports.
|
// Forward declaration of `Track` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { struct Track; }
|
namespace margelo::nitro::omni { struct Track; }
|
||||||
// Forward declaration of `Rendition` to properly resolve imports.
|
// Forward declaration of `Rendition` to properly resolve imports.
|
||||||
@@ -23,18 +25,16 @@ namespace margelo::nitro::omni { struct Rendition; }
|
|||||||
namespace margelo::nitro::omni { enum class PlayerStatus; }
|
namespace margelo::nitro::omni { enum class PlayerStatus; }
|
||||||
// Forward declaration of `CastStatus` to properly resolve imports.
|
// Forward declaration of `CastStatus` to properly resolve imports.
|
||||||
namespace margelo::nitro::omni { enum class CastStatus; }
|
namespace margelo::nitro::omni { enum class CastStatus; }
|
||||||
// Forward declaration of `Source` to properly resolve imports.
|
|
||||||
namespace margelo::nitro::omni { struct Source; }
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "HybridOmniEventMapSpec.hpp"
|
#include "HybridOmniEventMapSpec.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include "Source.hpp"
|
||||||
#include "Track.hpp"
|
#include "Track.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Rendition.hpp"
|
#include "Rendition.hpp"
|
||||||
#include "PlayerStatus.hpp"
|
#include "PlayerStatus.hpp"
|
||||||
#include "CastStatus.hpp"
|
#include "CastStatus.hpp"
|
||||||
#include "Source.hpp"
|
|
||||||
|
|
||||||
namespace margelo::nitro::omni {
|
namespace margelo::nitro::omni {
|
||||||
|
|
||||||
@@ -66,6 +66,8 @@ namespace margelo::nitro::omni {
|
|||||||
virtual std::shared_ptr<HybridOmniEventMapSpec> getEventMap() = 0;
|
virtual std::shared_ptr<HybridOmniEventMapSpec> getEventMap() = 0;
|
||||||
virtual std::optional<bool> getShowNotification() = 0;
|
virtual std::optional<bool> getShowNotification() = 0;
|
||||||
virtual void setShowNotification(std::optional<bool> showNotification) = 0;
|
virtual void setShowNotification(std::optional<bool> showNotification) = 0;
|
||||||
|
virtual std::optional<Source> getSource() = 0;
|
||||||
|
virtual void setSource(const std::optional<Source>& source) = 0;
|
||||||
virtual bool getHasPrev() = 0;
|
virtual bool getHasPrev() = 0;
|
||||||
virtual bool getHasNext() = 0;
|
virtual bool getHasNext() = 0;
|
||||||
virtual std::vector<Track> getVideos() = 0;
|
virtual std::vector<Track> getVideos() = 0;
|
||||||
@@ -89,7 +91,6 @@ namespace margelo::nitro::omni {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Methods
|
// Methods
|
||||||
virtual void setSource(const std::optional<Source>& source) = 0;
|
|
||||||
virtual void play() = 0;
|
virtual void play() = 0;
|
||||||
virtual void pause() = 0;
|
virtual void pause() = 0;
|
||||||
virtual void seekBy(double offset) = 0;
|
virtual void seekBy(double offset) = 0;
|
||||||
|
|||||||
+3
-7
@@ -61,7 +61,7 @@ export class WebOmniPlayer implements OmniPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
castOptions: CastOptions | null = null;
|
castOptions: CastOptions | null = null;
|
||||||
_source: Source | null = null;
|
_source: Source | undefined = undefined;
|
||||||
private _showNotification = false;
|
private _showNotification = false;
|
||||||
|
|
||||||
// Selected ASS/PGS subtitle (drawn by the overlay); `null` when the active
|
// Selected ASS/PGS subtitle (drawn by the overlay); `null` when the active
|
||||||
@@ -70,15 +70,11 @@ export class WebOmniPlayer implements OmniPlayer {
|
|||||||
private overlaySubtitle: Subtitle | null = null;
|
private overlaySubtitle: Subtitle | null = null;
|
||||||
private overlayListeners = new Set<() => void>();
|
private overlayListeners = new Set<() => void>();
|
||||||
|
|
||||||
get source(): Source | null {
|
get source(): Source | undefined {
|
||||||
return this._source;
|
return this._source;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSource(source?: Source): void {
|
set source(source: Source | undefined) {
|
||||||
this.source = source ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
set source(source: Source | null) {
|
|
||||||
this._source = source;
|
this._source = source;
|
||||||
// Drop the overlay subtitle if it is not part of the new source.
|
// Drop the overlay subtitle if it is not part of the new source.
|
||||||
if (
|
if (
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ export const OmniProvider = ({
|
|||||||
const player = useLazyRef(() => ProviderFactory.createPlayer(source));
|
const player = useLazyRef(() => ProviderFactory.createPlayer(source));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
player.setSource(source);
|
player.source = source;
|
||||||
}, [source]);
|
}, [source]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ const PlayerInitializer = ({
|
|||||||
const seekedForSrc = useRef<string | undefined>(undefined);
|
const seekedForSrc = useRef<string | undefined>(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
player.source = source ?? null;
|
player.source = source;
|
||||||
const uri = source?.src[0]?.uri;
|
const uri = source?.src[0]?.uri;
|
||||||
if (uri !== seekedForSrc.current) {
|
if (uri !== seekedForSrc.current) {
|
||||||
seekedForSrc.current = uri;
|
seekedForSrc.current = uri;
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import type { Source } from "./source";
|
|||||||
export interface OmniPlayer extends OmniPlayerState {
|
export interface OmniPlayer extends OmniPlayerState {
|
||||||
showNotification?: boolean;
|
showNotification?: boolean;
|
||||||
|
|
||||||
setSource(source?: Source): void;
|
source?: Source;
|
||||||
|
|
||||||
play(): void;
|
play(): void;
|
||||||
pause(): void;
|
pause(): void;
|
||||||
|
|||||||
Reference in New Issue
Block a user