#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVPlayerViewController.h>
@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];
}
网友评论