我玩了 AVCam 演示示例,以添加一个播放器 (MPMoviePlayerController) 允许预览录制的视频
我在 xib 中添加了一个播放按钮以及相应的 IBOutlet 和 IBActions + 一个播放器:
@property (nonatomic,retain) IBOutlet UIBarButtonItem *playerButton;
@property (nonatomic, assign) MPMoviePlayerController *player;
- (IBAction)playVideo:(id)sender;
我确实在 viewdidload 中初始化了播放器:
player = [[MPMoviePlayerController alloc] init];
播放动作如下
- (IBAction)playVideo:(id)sender {
if(player) {
[player stop];
}
// Create a new movie player object.
[player setContentURL:[[[self captureManager] recorder] outputFileURL]];
player.movieSourceType = MPMovieSourceTypeFile;
[player prepareToPlay];
CGRect viewInsetRect = CGRectMake( 0, 0, 200, 300);
// Inset the movie frame in the parent view frame.
[[player view] setFrame:viewInsetRect];
player.scalingMode = MPMovieScalingModeAspectFill;
player.controlStyle = MPMovieControlStyleNone;
//player.useApplicationAudioSession = NO;
//[self.view addSubview: [_player view]];
[self.view addSubview:player.view];
if(player) {
[player play];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playComplete) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
}
播放结束时调用 playComplete :
-(void)playComplete {
[player.view removeFromSuperview];
}
结果:当我启动应用程序时,我可以录制任意数量的视频。当我播放最后录制的视频时,我可以毫无问题地播放它,但是在播放视频后,如果我再次尝试录制,我会在开始录制时遇到此错误:
错误域=AVFoundationErrorDomain 代码=-11803 “无法录制” UserInfo=0x152e60 {NSLocalizedRecoverySuggestion=再次尝试录制。,AVErrorRecordingSuccessfullyFinishedKey=false,NSLocalizedDescription=无法录制}
我认为这是临时输出文件的问题,但似乎不是。
我想知道引入 MPMoviePlayerController 是否会以某种我无法弄清楚的方式破坏应用程序的行为。
你们有些人有什么想法吗?
谢谢
磷