iOS 视频播放实现:AVPlayerViewController

直接上代码

- (void)viewDidLoad {

    [super viewDidLoad];

    [self.view addSubview:self.moviePlayer.view];

    [self.moviePlayer.player play];

}

 

-(AVPlayerViewController *)moviePlayer{

    if (!_moviePlayer) {

        NSURL * url = [NSURL URLWithString:@"http://v.cctv.com/flash/mp4video6/TMS/2011/01/05/cf752b1c12ce452b3040cab2f90bc265_h264818000nero_aac32-1.mp4"];

        _moviePlayer=[[AVPlayerViewController alloc]init];

        _moviePlayer.player = [AVPlayer playerWithURL:url];

        _moviePlayer.view.frame=self.view.bounds;

        _moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

        _moviePlayer.showsPlaybackControls = YES;

        [self.view addSubview:_moviePlayer.view];

    }

    return _moviePlayer;

}

iOS9.0后要求请求都要使用https,demo中的视频是http的,需要再info.plist文件中加入:App Transport Security Settings(字典),在里面加入Allow Arbitrary Loads(设置为YES)

重新运行,可以播放视频了.

 

iOS 视频播放实现:AVPlayerViewController_第1张图片

你可能感兴趣的:(iphone开发资料,视频播放)