AvplayerViewController portrait only

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

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    I display video in this way.
    Code:
    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

    Joined:
    Oct 2, 2010
    #2
    Select portrait as the only orientation for the app.
     
  3. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #3
    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