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

时间:2022-08-22 14:06:38

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

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

 #import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h> @interface ViewController () /* 创建播放控制器 */
@property (nonatomic, strong) MPMoviePlayerViewController *playerVc;
- (IBAction)play; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
} #pragma mark - 懒加载代码
- (MPMoviePlayerViewController *)playerVc
{
if (_playerVc == nil) {
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"]; _playerVc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
}
return _playerVc;
} - (IBAction)play {
[self presentViewController:self.playerVc animated:YES completion:nil];
} @end