Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
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 ?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.