Skip to content
Prev Previous commit
Next Next commit
Simplify significantly
  • Loading branch information
stuartmorgan-g committed Jul 8, 2025
commit d60140c2c1579e4d08e51fa3545f1bfab275f117
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,21 @@
#import "../video_player_avfoundation/include/video_player_avfoundation/FVPNativeVideoView.h"

#import <AVFoundation/AVFoundation.h>

@interface FVPPlayerView : NSView
@property(nonatomic, strong) AVPlayerLayer *playerLayer;
@end

@implementation FVPPlayerView

- (CALayer *)makeBackingLayer {
return [AVPlayerLayer playerLayerWithPlayer:nil];
}

- (instancetype)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
self.wantsLayer = YES;
return self;
}

- (void)setPlayer:(AVPlayer *)player {
((AVPlayerLayer *)self.layer).player = player;
}

@end

@interface FVPNativeVideoView ()
@property(nonatomic, strong) FVPPlayerView *playerView;
@end
#import <QuartzCore/QuartzCore.h>

@implementation FVPNativeVideoView

- (instancetype)initWithPlayer:(AVPlayer *)player {
self = [super init];
if (self) {
_playerView = [[FVPPlayerView alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
[_playerView setPlayer:player];
[self addSubview:_playerView];

// Add constraints to ensure the playerView resizes with its parent.
_playerView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[_playerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[_playerView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[_playerView.topAnchor constraintEqualToAnchor:self.topAnchor],
[_playerView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
]];
self.wantsLayer = YES;
((AVPlayerLayer *)self.layer).player = player;
}
return self;
}

- (FVPPlayerView *)view {
return self.playerView;
- (CALayer *)makeBackingLayer {
return [AVPlayerLayer playerLayerWithPlayer:nil];
}

@end