AVPlayerViewController video player, avplayercontroller

Source: Internet
Author: User

AVPlayerViewController video player, avplayercontroller
Preface

After iOS8, the system uses AVPlayerViewController to play videos.

AVPlayerViewController

AVPlayerViewController is similar to the navigation controller. You need to add it to a View Controller and add its view to the view.

1. Import the header file
#import <AVKit/AVKit.h>#import <AVFoundation/AVFoundation.h>
2. Declare member variables
   AVPlayerViewController      *_playerController;    AVPlayer                    *_player;    AVAudioSession              *_session;    NSString                    *_urlString;
3. Use a player
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self. view. backgroundColor = [UIColor whiteColor]; _ session = [AVAudioSession sharedInstance]; [_ session setCategory: AVAudioSessionCategoryPlayback error: nil]; _ player = [AVPlayer playerWithURL: [NSURL URLWithString: @ "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]; _ playerController = [[AVPlayerViewController alloc] init]; _ playerController. player = _ player; _ playerController. videoGravity = AVLayerVideoGravityResizeAspect; _ playerController. allowsPictureInPicturePlayback = true; // picture-in-picture, iPad _ playerController. showsPlaybackControls = true; [self addChildViewController: _ playerController]; _ playerController. view. translatesAutoresizingMaskIntoConstraints = true; // AVPlayerViewController may be written with constraints internally. This statement can disable automatic constraints and eliminate the error/self. view. bounds _ playerController. view. frame = CGRectMake (0, 0,320,300); [self. view addSubview: _ playerController. view]; [_ playerController. player play]; // automatic playback}
4. If you want to use an iOS9 image in-picture (tablet only)

:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.