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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值