iOS开发--利用MPMoviePlayerController播放视频简单实现

一.包含头文件#import <MediaPlayer/MediaPlayer.h>

二.重点:给MPMoviePlayerController的view设置frame,并且将view添加到某一个view上

 1 #import "ViewController.h"
 2 #import <MediaPlayer/MediaPlayer.h>
 3 
 4 @interface ViewController ()
 5 
 6 /* 播放器 */
 7 @property (nonatomic, strong) MPMoviePlayerController *player;
 8 - (IBAction)play;
 9 
10 @end
11 
12 @implementation ViewController
13 
14 - (void)viewDidLoad {
15     [super viewDidLoad];
16 }
17 
18 - (MPMoviePlayerController *)player
19 {
20     if (_player == nil) {
21         NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"];
22         
23         _player = [[MPMoviePlayerController alloc] initWithContentURL:url];
24         
25         // 设置控制器View所在的位置
26         _player.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width * 9 / 16);
27         
28         // 设置播放器的控制模式
29         _player.controlStyle = MPMovieControlStyleFullscreen;
30         
31         [self.view addSubview:self.player.view];
32     }
33     return _player;
34 }
35 
36 - (IBAction)play {
37     [self.player play];
38 }
39 
40 @end
原文地址:https://www.cnblogs.com/gchlcc/p/5583554.html