一、简介
NSAssert(self.url, @"URL不能为空");
[[MPMoviePlayerController alloc] initWithContentURL:self.url];
[self.view addSubview:self.moviePlayer.view];
通过设置AutoresizingMask属性可以在横竖屏转换时自动调整视图大小
[self.moviePlayer play];
[self.moviePlayer setFullscreen:YES animated:YES];
MPMoviePlayerPlaybackStateDidChangeNotification
MPMoviePlayerPlaybackDidFinishNotification
MPMoviePlayerDidExitFullscreenNotification
MPMoviePlayerThumbnailImageRequestDidFinishNotification
-requestThumbnailImagesAtTimes:timeOption:
五、VLC(基于FFmpeg)
1.集成
#import "VLCMediaPlayer.h"
self.vlcPlayer = [[VLCMediaPlayer alloc] init];
self.vlcPlayer.drawable = self.view;
self.vlcPlayer.media = [VLCMedia mediaWithURL:[NSURL URLWithString:@"http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"]];
[self.vlcPlayer play];
- (BOOL)play;
- (void)pause;
- (void)stop;
- (BOOL)isPlaying;
@property float rate; // 播放速率
- (void)setTime:(VLCTime *)value; // 当前的播放时间
- (VLCTime *)time;
@property (readonly) VLCTime *remainingTime; // 剩余的播放时间
- (void)setPosition:(float)newPosition; // 播放进度(0.0 ~ 1.0)
- (float)position;
- (void)setMedia:(VLCMedia *)value;
- (VLCMedia *)media;
@property (retain) id drawable;
2.VLCMediaPlayer – 播放器的状态
enum {
VLCMediaPlayerStateStopped, // 播放器已经停止
VLCMediaPlayerStateOpening, // 流正在打开
VLCMediaPlayerStateBuffering, // 流正在缓冲
VLCMediaPlayerStateEnded, // 流已经结束
VLCMediaPlayerStateError, // 播放器产生了错误
VLCMediaPlayerStatePlaying, // 流正在播放
VLCMediaPlayerStatePaused // 流被暂停了
};
3.VLCMediaPlayerDelegate
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification;
- (void)mediaPlayerTimeChanged:(NSNotification *)aNotification;
1 // 2 // ViewController.m 3 // IOS_0322_视频 4 // 5 // Created by ma c on 16/3/22. 6 // Copyright © 2016年 博文科技. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 #import <MediaPlayer/MediaPlayer.h> 11 #import <MobileVLCKit/MobileVLCKit.h> 12 13 @interface ViewController () 14 15 @property (nonatomic, strong) VLCMediaPlayer *player; 16 17 @end 18 19 @implementation ViewController 20 21 - (void)viewDidLoad { 22 [super viewDidLoad]; 23 self.view.backgroundColor = [UIColor cyanColor]; 24 25 } 26 27 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event 28 { 29 // [self systemMoviePlayer]; 30 [self mobileVLCMoviePlayer]; 31 32 } 33 34 - (void)mobileVLCMoviePlayer 35 { 36 NSURL *url = [[NSBundle mainBundle] URLForResource:@"11-传感器.mp4" withExtension:nil]; 37 self.player = [[VLCMediaPlayer alloc] init]; 38 self.player.media = [VLCMedia mediaWithURL:url]; 39 40 //设置播放界面的载体 41 self.player.drawable = self.view; 42 //播放 43 [self.player play]; 44 45 } 46 47 - (void)systemMoviePlayer 48 { 49 MPMoviePlayerController *mpc = [[MPMoviePlayerController alloc] init]; 50 mpc.contentURL = [[NSBundle mainBundle] URLForResource:@"11-传感器.mp4" withExtension:nil]; 51 52 //缓冲之后自动播放 53 // [mpc prepareToPlay]; 54 55 //隐藏自带的控制面板 56 // mpc.controlStyle = MPMovieControlStyleNone; 57 58 //添加播放器的界面到控制器View上面 59 mpc.view.frame = CGRectMake(7, 50, 400, 300); 60 [self.view addSubview:mpc.view]; 61 62 //播放 63 [mpc play]; 64 65 } 66 67 @end