feat: add loop property for iOS (#3)
This commit is contained in:
parent
e213055c51
commit
1327fc622f
|
@ -3,5 +3,6 @@
|
|||
@interface RCT_EXTERN_MODULE(TransparentVideoViewManager, RCTViewManager)
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(loop, BOOL);
|
||||
|
||||
@end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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} />;
|
||||
|
|
Loading…
Reference in New Issue