工具栏须要自定义订制。 #import <AVFoundation/AVFoundation.h> @property (nonatomic, strong)AVPlayer *player; -(AVPlayer *)player { if (_player == nil) { //1.获取URL(远程/本地) NSURL *url = [[NSBundle mainBundle] URLForResource:@"周杰伦.mp4" withExtension:nil]; //NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"]; //2.建立AVPlayerItem AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url]; //3.建立AVPlayer _player = [AVPlayer playerWithPlayerItem:item]; //4.添加AVPlayerLayer AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_player]; layer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 9/16); layer.backgroundColor = [UIColor redColor].CGColor; [self.view.layer addSublayer:layer]; } return _player; } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self.player play]; }
自带工具栏,有很是多通知方法。 #import <MediaPlayer/MediaPlayer.h> @property (nonatomic ,strong)MPMoviePlayerController *playController; -(MPMoviePlayerController *)playController { if (_playController == nil) { //1.获取视频的URL NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/3e35cbb0-c8e5-4827-9614-b5a355259010/L.mp4"]; //2.建立控制器 _playController = [[MPMoviePlayerController alloc] initWithContentURL:url]; //3.设置控制器的View的位置 _playController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 9/16); //4.将view添加到控制器上 [self.view addSubview:_playController.view]; //5.设置属性,隐藏工具栏 // _playController.controlStyle = MPMovieControlStyleNone; } return _playController; } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self.playController play]; }
全屏播放 #import <MediaPlayer/MediaPlayer.h> @property (nonatomic ,strong)MPMoviePlayerViewController *playViewContrller; -(MPMoviePlayerViewController *)playViewContrller { if (_playViewContrller == nil) { NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/3e35cbb0-c8e5-4827-9614-b5a355259010/L.mp4"]; _playViewContrller = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; } return _playViewContrller; } -(void)play { [self presentMoviePlayerViewControllerAnimated:self.playViewContrller]; }
1.AVAudioPlayer(本地音乐)框架
2.AVPlayer(远程音乐/播放视频)-> 添加到layer工具
3.MPMoviePlayerController -> 给view设置frame,将这个view添加到某个view上atom
4.MPMoviePlayerViewController(modal出来,自动播放,必定会全屏播放)url
表明框架:kxmovie(最简易) VLC FFMpegspa