mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-08-16 02:56:22 +00:00
feat: override dispose method in VideoPlayer to cleanup resources
This commit is contained in:
@@ -103,5 +103,9 @@ namespace margelo::nitro::video {
|
||||
return __promise;
|
||||
}();
|
||||
}
|
||||
void JHybridVideoPlayerSpec::clean() {
|
||||
static const auto method = _javaPart->getClass()->getMethod<void()>("clean");
|
||||
method(_javaPart);
|
||||
}
|
||||
|
||||
} // namespace margelo::nitro::video
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace margelo::nitro::video {
|
||||
void play() override;
|
||||
void pause() override;
|
||||
std::shared_ptr<Promise<void>> replaceSourceAsync(const std::shared_ptr<margelo::nitro::video::HybridVideoPlayerSourceSpec>& source) override;
|
||||
void clean() override;
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
+4
@@ -78,6 +78,10 @@ abstract class HybridVideoPlayerSpec: HybridObject() {
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
abstract fun replaceSourceAsync(source: HybridVideoPlayerSourceSpec): Promise<Unit>
|
||||
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
abstract fun clean(): Unit
|
||||
|
||||
private external fun initHybrid(): HybridData
|
||||
|
||||
|
||||
@@ -102,6 +102,12 @@ namespace margelo::nitro::video {
|
||||
auto __value = std::move(__result.value());
|
||||
return __value;
|
||||
}
|
||||
inline void clean() override {
|
||||
auto __result = _swiftPart.clean();
|
||||
if (__result.hasError()) [[unlikely]] {
|
||||
std::rethrow_exception(__result.error());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ReactNativeVideo::HybridVideoPlayerSpec_cxx _swiftPart;
|
||||
|
||||
@@ -21,6 +21,7 @@ public protocol HybridVideoPlayerSpec_protocol: AnyObject {
|
||||
func play() throws -> Void
|
||||
func pause() throws -> Void
|
||||
func replaceSourceAsync(source: (any HybridVideoPlayerSourceSpec)) throws -> Promise<Void>
|
||||
func clean() throws -> Void
|
||||
}
|
||||
|
||||
/// See ``HybridVideoPlayerSpec``
|
||||
|
||||
+11
@@ -200,4 +200,15 @@ public class HybridVideoPlayerSpec_cxx {
|
||||
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func clean() -> bridge.Result_void_ {
|
||||
do {
|
||||
try self.__implementation.clean()
|
||||
return bridge.create_Result_void_()
|
||||
} catch (let __error) {
|
||||
let __exceptionPtr = __error.toCpp()
|
||||
return bridge.create_Result_void_(__exceptionPtr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,11 @@ namespace margelo::nitro::video {
|
||||
prototype.registerHybridMethod("play", &HybridVideoPlayerSpec::play);
|
||||
prototype.registerHybridMethod("pause", &HybridVideoPlayerSpec::pause);
|
||||
prototype.registerHybridMethod("replaceSourceAsync", &HybridVideoPlayerSpec::replaceSourceAsync);
|
||||
prototype.registerHybridMethod("clean", &HybridVideoPlayerSpec::clean);
|
||||
});
|
||||
}
|
||||
|
||||
void HybridVideoPlayerSpec::dispose() {
|
||||
clean();
|
||||
}
|
||||
} // namespace margelo::nitro::video
|
||||
|
||||
@@ -60,10 +60,12 @@ namespace margelo::nitro::video {
|
||||
virtual void play() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual std::shared_ptr<Promise<void>> replaceSourceAsync(const std::shared_ptr<margelo::nitro::video::HybridVideoPlayerSourceSpec>& source) = 0;
|
||||
virtual void clean() = 0;
|
||||
|
||||
protected:
|
||||
// Hybrid Setup
|
||||
void loadHybridMethods() override;
|
||||
void dispose() override;
|
||||
|
||||
protected:
|
||||
// Tag for logging
|
||||
|
||||
@@ -50,6 +50,11 @@ export interface VideoPlayer
|
||||
* see {@link VideoPlayerSource}
|
||||
*/
|
||||
replaceSourceAsync(source: VideoPlayerSource): Promise<void>;
|
||||
|
||||
/**
|
||||
* Release the player resources.
|
||||
*/
|
||||
clean(): void;
|
||||
}
|
||||
|
||||
export interface VideoPlayerFactory
|
||||
|
||||
Reference in New Issue
Block a user