美文网首页
iOS 使用自带视频播放器播放视频

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

作者: DH_Fantasy | 来源:发表于2017-02-12 21:15 被阅读486次
#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];

}

相关文章

网友评论

      本文标题:iOS 使用自带视频播放器播放视频

      本文链接:https://www.haomeiwen.com/subject/chlqettx.html