导入 MediaPlayer.framework
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:@"test1" ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:path];
_playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 40);
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
(void)play{
[self presentMoviePlayerViewControllerAnimated:_playerController];
//播放
[_playerController.moviePlayer play];
}</pre>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。