1

I am doing the implementation of video splash similar to Uber in my application. I had added two buttons in the storyboard at the bottom part with equal spacing in storyboard. Now i am adding AVPlayer to play a video present in NSBundle. While running the application the video is playing but i cant see my buttons at the bottom part. Why it is happening? Please suggest..

   - (void)createVideoPlayer {

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"welcome_video" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];

    self.player = [AVPlayer playerWithPlayerItem:playerItem];
    self.player.volume = PLAYER_VOLUME;

    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.videoGravity = UIViewContentModeScaleToFill;
    playerLayer.frame = self.playerView.layer.bounds;
    [self.playerView.layer addSublayer:playerLayer];

    [self.player play];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
}

- (void)moviePlayDidEnd:(NSNotification*)notification{

    AVPlayerItem *item = [notification object];
    [item seekToTime:kCMTimeZero];
    [self.player play];
}

The screenshot of buttons in storyboard: enter image description here

The output in simulator:

enter image description here

You can see buttons are missing and Note: constraints of these buttons are correct and i can see them in every preview...

Jessica thompson
  • 407
  • 2
  • 8
  • 20

2 Answers2

1

You can try calling bringSubviewToFront on the button after you've added the avplayer.

JingJingTao
  • 1,760
  • 17
  • 28
1

You need to call bringSubviewToFront to bring your Button outlet front and visible on AVPlayer after adding AVPlyer instance in your view.

[self.view bringSubviewToFront:buttonOutlet];
Nirav D
  • 71,513
  • 12
  • 161
  • 183