AVPlayerLayer
및 AVPlayer
으로 내 앱에 비디오 플레이어를 빌드합니다.AVPlayerLayer 및 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];
지금, 장치가 비디오를 재생 시작하지이 방법을 수행 몇 번 (그것의 동시성을 발생하지 같은 동영상). 왜 그런 일이 일어 났을까요? 어떻게 처리 할 수 있습니까?
편집
나는 5 곡을 연주 한 후 일어난 것으로 나타났습니다.
avplayer에서 대리자 메서드를 사용할 수있는 이유는 무엇입니까? audioplayer.delegate = nil로 설정하고 audioplayer를 nil로 설정하고 새 플레이어를 초기화하는 동안 델리게이트를 self로 설정하십시오. –
AVPlayer에 대리자 메소드가 있습니까? 확실합니까? – MTA
미안하지만, 델리게이트 메서드가있는 AVAudioplayer는 혼란 스럽습니다. –