我的代码是:
-(void)playMoviesForItems:(NSArray *)shopItems{
_moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:@"videoPlayerController"];
[_moviePlayer playMoviesForItems:shopItems];
[self presentViewController:_moviePlayer animated:NO completion:^{
[self.scrollView scrollRectToVisible:CGRectZero animated:YES];
}];
}
在包含 presentViewController 的行中,我得到
EXC_BAD_ACCESS (code=1, address=.....)
我找不到我为什么会得到这个。我哪里错了?我该如何调试呢?
更新:电影播放器声明如下:
@property(nonatomic,retain) VideoPlayerViewController* moviePlayer;
VideoPlayerController 中的代码是:
-(VideoPlayerViewController*)playMoviesForItems:(NSArray*)items{
playerItems = [[NSMutableArray alloc] init];
for (ShopItem* item in items) {
NSURL *url = [NSURL fileURLWithPath:item.localUrl];
AVPlayerItem *videoItem = [AVPlayerItem playerItemWithURL:url];
[playerItems addObject:videoItem];
}
self.mPlayer = [[AVQueuePlayer alloc] init];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:mPlayer];
self.playerLayer.bounds = self.view.bounds;
self.view.backgroundColor = [UIColor blackColor];
[mPlaybackView setPlayer:self.mPlayer];
currentIndex = 0;
[self initScrubberTimer];
[self playAtIndex:currentIndex];
mScrubber.maximumValue = CMTimeGetSeconds(self.mPlayer.currentItem.duration);
mScrubber.value = 0.0;
[self syncScrubber];
[self showOverlays];
return self;
}
有时它工作得很清楚。但有时它会破裂。