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

一.MPMoviePlayerViewController和MPMoviePlayerController区分开,前者继承自NSObject,后者继承自UIViewController

二.MPMoviePlayerViewController只能用modal出来的形式播放,并且一定是全屏的播放

 1 #import "ViewController.h"
 2 #import <MediaPlayer/MediaPlayer.h>
 3 
 4 @interface ViewController ()
 5 
 6 /* 创建播放控制器 */
 7 @property (nonatomic, strong) MPMoviePlayerViewController *playerVc;
 8 - (IBAction)play;
 9 
10 @end
11 
12 @implementation ViewController
13 
14 - (void)viewDidLoad {
15     [super viewDidLoad];
16 }
17 
18 #pragma mark - 懒加载代码
19 - (MPMoviePlayerViewController *)playerVc
20 {
21     if (_playerVc == nil) {
22         NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"];
23         
24         _playerVc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
25     }
26     return _playerVc;
27 }
28 
29 - (IBAction)play {
30     [self presentViewController:self.playerVc animated:YES completion:nil];
31 }
32 
33 @end

 

posted @ 2016-06-14 11:58  Chaos_G  阅读(635)  评论(0编辑  收藏  举报