feat: add duration property to player

This commit is contained in:
Krzysztof Moch
2024-12-13 14:55:25 +01:00
parent 237cc6e157
commit 8d830243a4
11 changed files with 31 additions and 0 deletions
@@ -28,6 +28,9 @@ class HybridVideoPlayer() : HybridVideoPlayerSpec() {
get() = runOnMainThreadSync { return@runOnMainThreadSync player.volume.toDouble() }
set(value) = runOnMainThread { player.volume = value.toFloat() }
override val duration: Double
get() = runOnMainThreadSync { return@runOnMainThreadSync player.duration.toDouble() }
private fun initializePlayerFromSource(source: HybridVideoPlayerSource) {
this.source = source
+4
View File
@@ -36,6 +36,10 @@ class HybridVideoPlayer: HybridVideoPlayerSpec {
}
}
var duration: Double {
Double(player.currentItem?.duration.seconds ?? Double.nan)
}
init(source: HybridVideoPlayerSourceSpec) throws {
self.source = source
@@ -60,6 +60,11 @@ namespace margelo::nitro::video {
static const auto method = _javaPart->getClass()->getMethod<void(double /* currentTime */)>("setCurrentTime");
method(_javaPart, currentTime);
}
double JHybridVideoPlayerSpec::getDuration() {
static const auto method = _javaPart->getClass()->getMethod<double()>("getDuration");
auto __result = method(_javaPart);
return __result;
}
// Methods
void JHybridVideoPlayerSpec::play() {
@@ -53,6 +53,7 @@ namespace margelo::nitro::video {
void setVolume(double volume) override;
double getCurrentTime() override;
void setCurrentTime(double currentTime) override;
double getDuration() override;
public:
// Methods
@@ -55,6 +55,10 @@ abstract class HybridVideoPlayerSpec: HybridObject() {
@set:DoNotStrip
@set:Keep
abstract var currentTime: Double
@get:DoNotStrip
@get:Keep
abstract val duration: Double
// Methods
@DoNotStrip
@@ -76,6 +76,9 @@ namespace margelo::nitro::video {
inline void setCurrentTime(double currentTime) noexcept override {
_swiftPart.setCurrentTime(std::forward<decltype(currentTime)>(currentTime));
}
inline double getDuration() noexcept override {
return _swiftPart.getDuration();
}
public:
// Methods
@@ -32,6 +32,7 @@ public protocol HybridVideoPlayerSpec: AnyObject, HybridObjectSpec {
var source: (any HybridVideoPlayerSourceSpec) { get set }
var volume: Double { get set }
var currentTime: Double { get set }
var duration: Double { get }
// Methods
func play() throws -> Void
@@ -135,6 +135,13 @@ public class HybridVideoPlayerSpecCxx {
self.__implementation.currentTime = newValue
}
}
public var duration: Double {
@inline(__always)
get {
return self.__implementation.duration
}
}
// Methods
@inline(__always)
@@ -20,6 +20,7 @@ namespace margelo::nitro::video {
prototype.registerHybridSetter("volume", &HybridVideoPlayerSpec::setVolume);
prototype.registerHybridGetter("currentTime", &HybridVideoPlayerSpec::getCurrentTime);
prototype.registerHybridSetter("currentTime", &HybridVideoPlayerSpec::setCurrentTime);
prototype.registerHybridGetter("duration", &HybridVideoPlayerSpec::getDuration);
prototype.registerHybridMethod("play", &HybridVideoPlayerSpec::play);
prototype.registerHybridMethod("pause", &HybridVideoPlayerSpec::pause);
});
@@ -52,6 +52,7 @@ namespace margelo::nitro::video {
virtual void setVolume(double volume) = 0;
virtual double getCurrentTime() = 0;
virtual void setCurrentTime(double currentTime) = 0;
virtual double getDuration() = 0;
public:
// Methods
+1
View File
@@ -6,6 +6,7 @@ export interface VideoPlayer
source: VideoPlayerSource;
volume: number;
currentTime: number;
readonly duration: number;
play(): void;
pause(): void;