我用<代码>AVPlayer Layer<>/code>和AVPlayer
在座打上录像机。
在选择新录像时,采用这种方法:
//this to remove the current video
if (avPlayerLayer) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:[audioPlayer currentItem]];
[avPlayerLayer.player pause];
[avPlayerLayer removeFromSuperlayer];
avPlayerLayer = nil;
}
//and this is to add a new one
audioPlayer = [[AVPlayer alloc]initWithURL:[NSURL fileURLWithPath:fileName]];
avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:audioPlayer] retain];
[avPlayerLayer setFrame:self.view.bounds];
CGRect frame = avPlayerLayer.frame;
[avPlayerLayer setFrame:CGRectMake(frame.origin.x, frame.origin.y - 30, frame.size.width, frame.size.height)];
[[self.view layer] addSublayer:avPlayerLayer];
[audioPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishPlayingSong)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[audioPlayer currentItem]];
[audioPlayer release];
现在,在我使用这种方法时,有些时候,该装置不开始拍摄录像(其发生是同步的,而不是在同一录像上)。 为什么会发生? 如何处置?
Edit
我注意到,这发生在我玩五歌之后。