3

I have an AVPlayerView as the 2nd NSSplitViewItem in a NSSplitViewController. The 1st split item is a list of videos. When I select a video, it plays in the AVPlayerView. The problem is, after I call [self.videoView.player play]; my MediaViewController's view resizes depending on the size of the video being played.

I'm using StoryBoards and my MediaViewController on the canvas has the AVPlayerView Top/Bottom/Trailing/Leading set to hug the superview. This seems to work fine by letting the window be resized and the video adjusts size accordingly.

I don't understand at what point the view decides to resize itself and what to do to stop it.

I have set self.videoView.videoGravity = AVLayerVideoGravityResizeAspect;

What am I missing?

Thanks

EDIT ---------

It seems the problem is not with the video size, but an image overlay I have added to the videoPlayer contentOverlayView.

I add the overlay like this:

if (self.videoView.contentOverlayView.subviews.count == 0)
{
    // Add an NSImageView subview to use for overlays
    NSImageView *overlayIV = [[NSImageView alloc] initWithFrame:self.videoView.frame];
    [overlayIV setTranslatesAutoresizingMaskIntoConstraints:NO];
    [overlayIV setImageScaling:NSImageScaleProportionallyUpOrDown];
    [self.videoView.contentOverlayView addSubview:overlayIV];

    // Set constraints to hug parent
    [self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:overlayIV
                                                               attribute:NSLayoutAttributeTop
                                                               relatedBy:NSLayoutRelationEqual
                                                                  toItem:self.videoView
                                                               attribute:NSLayoutAttributeTop
                                                              multiplier:1.0
                                                                constant:0.0]];

    [self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:overlayIV
                                                               attribute:NSLayoutAttributeBottom
                                                               relatedBy:NSLayoutRelationEqual
                                                                  toItem:self.videoView
                                                               attribute:NSLayoutAttributeBottom
                                                              multiplier:1.0
                                                                constant:0.0]];

    [self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:overlayIV
                                                               attribute:NSLayoutAttributeLeading
                                                               relatedBy:NSLayoutRelationEqual
                                                                  toItem:self.videoView
                                                               attribute:NSLayoutAttributeLeading
                                                              multiplier:1.0
                                                                constant:0.0]];

    [self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:overlayIV
                                                               attribute:NSLayoutAttributeTrailing
                                                               relatedBy:NSLayoutRelationEqual
                                                                  toItem:self.videoView
                                                               attribute:NSLayoutAttributeTrailing
                                                              multiplier:1.0
                                                                constant:0.0]];
}

Then when I add a new image overlay it sometimes resizes the window:

NSImageView *overlayIV = [self.videoView.contentOverlayView.subviews firstObject];
if (overlayIV)
{
    if (image)
    {
        overlayIV.image = image;
    }
    else
    {
        overlayIV.image = nil;
    }
}
Darren
  • 10,182
  • 20
  • 95
  • 162
  • Can you link a minimal project where the problem occurs? Or the whole project is it's not very big? – vrwim May 19 '15 at 17:54

0 Answers0