去除這裏是我的代碼MPMoviePlayerController.view沒有從上海華
- (void)viewDidLoad
{
...
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:_moviePlayerController.view];
_moviePlayerController.fullscreen = YES;
_moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
_moviePlayerController.controlStyle=MPMovieControlStyleDefault;
[_moviePlayerController play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieIsOver:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
- (void)movieIsOver:(NSNotification *)notification
{
NSLog(@"movie is over");
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.moviePlayerController.view removeFromSuperview];//moviePlayerController is MPMoviePlayerController
}
當影片播放到結束,我不能看到「電影是在」日誌和moviePlayerController.view不除去。我不知道爲什麼。
編輯: MPMoviePlayerPlaybackDidFinishNotification工作well.I看 「電影是在」 log.The問題moviePlayerController.view不會被刪除。
請張貼用於啓動電影播放 – Stavash
@Stavash我發佈的代碼。 –
你是如何定義'moviePlayerController'的?在通知回調中,您是否檢查過控制器和視圖引用是否有效? – Wain