● iOS提供了叫 做MPMoviePlayerController、MPMoviePlayerViewController的两个 类,可以用来轻松播放视频
➢ YouTobe就是用MPMoviePlayerController实现的 ➢ MPMoviePlayerViewController只能全屏播放视频
● 上述两个类都定义在了MediaPlayer框架中
MPMoviePlayerController-01-加载资源
// 加载视频资源
NSString *urlString = [[NSBundle mainBundle]
pathForResource:@"sample_iTunes" ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:urlString];
// 创建播放器
_player = [[MPMoviePlayerController alloc]
initWithContentURL:url];
// 加载视频资源
NSString *urlString = [[NSBundle mainBundle] pathForResource:@"sample_iTunes" ofType:@"mov"];
NSString *urlString = [[NSBundle mainBundle] pathForResource:@"sample_iTunes" ofType:@"mov"];
NSURL *url = [NSURL fileURLWithPath:urlString];
// 创建播放器
_player = [[MPMoviePlayerController alloc]
initWithContentURL:url];
MPMoviePlayerController-02-显示
// 设置尺寸
_player.view.frame = self.view.bounds;
_player.view.frame = self.view.bounds;
_player.view.autoresizingMask =UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
// 添加到控制器的view上
[self.view addSubview:_player.view];
// 播放
[_player play];
MPMoviePlayerController-03-添加通知监听
// 监听播放状态的改变
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStateChange)
name:MPMoviePlayerPlaybackStateDidChangeNotification object:_player];
// 监听播放器结束全屏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen)
name:MPMoviePlayerDidExitFullscreenNotification object:_player];
MPMoviePlayerController其他属性
● 是否要自动播放
@property(nonatomic) BOOL shouldAutoplay;
@property(nonatomic) BOOL shouldAutoplay;
● 全屏显示
@property(nonatomic, getter=isFullscreen) BOOL
fullscreen;
- (void)setFullscreen:(BOOL)fullscreen animated:
(BOOL)animated;
● 截取视频中的图片
- (void)requestThumbnailImagesAtTimes:(NSArray
*)playbackTimes timeOption:(MPMovieTimeOption)option;
MPMoviePlayerViewController
● MPMoviePlayerViewController继承自UIViewController,它内部封装了一 个MPMoviePlayerController
● MPMoviePlayerViewController只能全屏播放
● 简单使用:
MPMoviePlayerViewController *play =
[[MPMoviePlayerViewController alloc] initWithContentURL:url];
其他
● 音频处理
➢ 依赖的框架:AVFoundation、AudioToolbox框架
➢ 依赖的框架:AVFoundation、AudioToolbox框架
➢ 播放长音乐:AVAudioPlayer
➢ 播放短音效:加载音频文件生成SystemSoundID
➢ 播放短音效:加载音频文件生成SystemSoundID
➢ 录音:AVAudioRecord
● 较为底层、高级的音频\视频处理
➢ CoreAudio、CoreVideo框架