我正在使用內置的MPMoviePlayerController播放視頻。使用兩個MPMoviePlayerControllers時遇到問題(請注意,沒有兩個視頻在同一時間播放)。我可以在第一個控制器上播放盡可能多的視頻,當我完成後處理它,然後分配另一個MPMoviePlayerController。當我設置controlStyle第二控制器上,我得到MPMoviePlayer錯誤的激活狀態?
終止應用程序一個SIGABRT由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「電影播放器已經錯激活狀態(1)
我已搜查在線並發現堆棧溢出的類似問題。那傢伙說他忘記了刪除回放完成通知。我相信我已經正確使用[[NSNotificationCenter defaultCenter] removeObserver:self];
我仍然崩潰。相當令人沮喪!
我不明白爲什麼它不可能使用兩個控制器,只要他們不是在同一時間播放。我寧願不必深入到AVPlayer的東西,只是爲了讓視頻工作。
謝謝!
編輯:註釋掉controlStyle賦值仍然會導致崩潰。下面是發佈的調用堆棧,以及該類中的幾個重要方法。
- (void) makePlayer;
{
[player.view removeFromSuperview];
[player release];
player = [MPMoviePlayerController new];
player.view.frame = self.bounds;
player.view.hidden = YES;
player.controlStyle = MPMovieControlStyleNone;
player.scalingMode = MPMovieScalingModeNone;
[self addSubview: player.view];
}
- (void) dealloc;
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[player.view removeFromSuperview];
[player release];
[super dealloc];
}
- (void) setMovieByName: (NSString *) name;
{
[self makePlayer];
player.shouldAutoplay = NO;
[player setContentURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: name ofType: @"mov"]]];
[player stop];
[player prepareToPlay];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(movieDimensionsKnown:) name:MPMovieNaturalSizeAvailableNotification object: player];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(playbackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object: player];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object: player];
}
- (void) playbackFinished: (NSNotification *) n
{
player.view.hidden = YES;
if ([delegate respondsToSelector: @selector(moviePlayerImageViewPlaybackDidFinish:)])
[delegate moviePlayerImageViewPlaybackDidFinish: self];
}
你應該顯示一些代碼,以便我們知道你是如何創建和處理電影控制器。順便說一下,如果你沒有設置controlStyle會怎麼樣?你仍然會得到例外,對吧? – MiguelB