feat: add loop property for iOS

This commit is contained in:
Brian Sztamfater 2023-08-15 13:21:03 -03:00
parent e213055c51
commit e1d58901e1
3 changed files with 14 additions and 3 deletions

View File

@ -3,5 +3,6 @@
@interface RCT_EXTERN_MODULE(TransparentVideoViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(loop, BOOL);
@end

View File

@ -26,6 +26,17 @@ class TransparentVideoView : UIView {
}
}
@objc var loop: Bool = Bool() {
didSet {
// Setup looping on our video
self.playerView?.isLoopingEnabled = loop
let player = self.playerView?.player
if (loop && (player?.rate == 0 || player?.error != nil)) {
player?.play()
}
}
}
func loadVideoPlayer(itemUrl: URL) {
if (self.playerView == nil) {
let playerView = AVPlayerView(frame: CGRect(origin: .zero, size: .zero))
@ -44,9 +55,6 @@ class TransparentVideoView : UIView {
let playerLayer: AVPlayerLayer = playerView.playerLayer
playerLayer.pixelBufferAttributes = [
(kCVPixelBufferPixelFormatTypeKey as String): kCVPixelFormatType_32BGRA]
// Setup looping on our video
playerView.isLoopingEnabled = true
NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackgound), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil)

View File

@ -6,6 +6,7 @@ import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'
type TransparentVideoProps = {
style: ViewStyle;
source?: any;
loop?: boolean;
};
const ComponentName = 'TransparentVideoView';
@ -27,6 +28,7 @@ class TransparentVideo extends React.PureComponent<TransparentVideoProps> {
uri,
type: source.type || '',
},
loop: nativeProps.loop ?? true,
});
return <TransparentVideoView {...nativeProps} />;