AvplayerViewController portrait only

Discussion in 'iOS Programming' started by erdinc27, Jul 20, 2017.

  1. erdinc27 macrumors regular

    Jul 20, 2011
    I display video in this way.
    NSURL *url = [NSURL URLWithString:banner.link];
            AVURLAsset *asset = [AVURLAsset assetWithURL: url];
            AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];
            AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem:item];
            self.playerViewController.player = player;
            self.playerViewController.showsPlaybackControls = true;
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:player.currentItem];
            [self.playerViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            self.playerViewController.showsPlaybackControls = true;
            //    [self.view addSubview:self.playerViewController.view];
            [self presentViewController:self.playerViewController animated:true completion:nil];
            [player play];
    the problem is user can rotate the application while video is played. I want the video to be played only in portrait mode. How it could be done ?
  2. bjet767 macrumors 6502a

    Oct 2, 2010
    Select portrait as the only orientation for the app.
  3. Mascots macrumors 68000


    Sep 5, 2009
    If you don't want the orientation of your app to be stuck in portrait and since this view is being presented: you can subclass UIViewController and override supportedInterfaceOrientations. Then embed your AVPlayerVC into a container on that subclassed ViewController.

Share This Page