iOS 使用自带视频播放器播放视频

#import "ViewController.h"
#import 
#import 

@interface ViewController ()

@property (nonatomic,strong) AVPlayerViewController *moviePlayerView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url= [NSURL URLWithString:@"test.mp4"];

    self.moviePlayerView = [[AVPlayerViewController alloc] init];

    AVPlayer *player = [AVPlayer playerWithURL:url];

    self.moviePlayerView.player = player;

    //设置界面缩放比例
    self.moviePlayerView.videoGravity = AVLayerVideoGravityResizeAspect;
}

- (IBAction)playAction:(id)sender {

    [self presentViewController:self.moviePlayerView animated:YES completion:NULL];

    [self.moviePlayerView.player play];

}

你可能感兴趣的:(iOS 使用自带视频播放器播放视频)