首页 > 代码库 > 音/视频处理

音/视频处理

1>音频播放

Ø依赖的框架:AVFoundation、AudioToolbox框架
Ø播放长音乐:AVAudioPlayer
Ø播放短音效:加载音频文件生成SystemSoundID
Ø录音:AVAudioRecord

 

2>视频播放

两个视频播放类的区别:

MPMoviePlayerController继承自NSObject;

MPMoviePlayerViewController继承自UIViewController,它内部封装了一个MPMoviePlayerController。
 
简单使用:
// 加载视频资源NSString *urlString = [[NSBundle mainBundle] pathForResource:@"sample_iTunes" ofType:@"mov"];NSURL *url = [NSURL fileURLWithPath:urlString];// 创建播放器_player = [[MPMoviePlayerController alloc] initWithContentURL:url];// 设置尺寸_player.view.frame = self.view.bounds;_player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;// 添加到控制器的view上[self.view addSubview:_player.view];// 播放[_player play];
// 监听播放状态的改变[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStateChange) 
    name:MPMoviePlayerPlaybackStateDidChangeNotification object:_player];// 监听播放器结束全屏[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen)
    name:MPMoviePlayerDidExitFullscreenNotification object:_player];

其它属性、方法:

是否要自动播放@property(nonatomic) BOOL shouldAutoplay;全屏显示@property(nonatomic, getter=isFullscreen) BOOL fullscreen;- (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated;截取视频中的图片- (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option;

 完整代码:视频播放

附:

1>添加图片到系统相册中

     UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:@"Default.png"], self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

2>导入视频到相册中
  UISaveVideoAtPathToSavedPhotosAlbum函数