一.包含头文件#import <MediaPlayer/MediaPlayer.h>
二.重点:给MPMoviePlayerController的view设置frame,并且将view添加到某一个view上
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h> @interface ViewController () /* 播放器 */
@property (nonatomic, strong) MPMoviePlayerController *player;
- (IBAction)play; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
} - (MPMoviePlayerController *)player
{
if (_player == nil) {
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"]; _player = [[MPMoviePlayerController alloc] initWithContentURL:url]; // 设置控制器View所在的位置
_player.view.frame = CGRectMake(, , self.view.bounds.size.width, self.view.bounds.size.width * / ); // 设置播放器的控制模式
_player.controlStyle = MPMovieControlStyleFullscreen; [self.view addSubview:self.player.view];
}
return _player;
} - (IBAction)play {
[self.player play];
} @end