我創建了一個全局變量:無法釋放的MPMoviePlayerController
MPMoviePlayerController *player;
我玩用下面的方法視頻:
- (IBAction爲)的playMovie:(的NSString *)videoName ViedeoType:(的NSString * )的VideoType {
ViewVideoSubview.alpha = 0;
NSString *url = [[NSBundle mainBundle]
pathForResource:videoName
ofType:videoType];
player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
player.shouldAutoplay =YES;
[ViewVideoSubview addSubview:player.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
和當視頻結束playi ng本身就是所謂的以下方法:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
[player.view removeFromSuperview]; //d1
MPMoviePlayerController *playerParam = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerParam];
[player release];
}
一切工作到目前爲止很好。問題是我有一個按鈕,當按下我需要加載另一個視圖控制器。我能夠加載該視圖控制器,但視頻仍在後臺播放。我不明白爲什麼我釋放播放器時出現錯誤。我的臨時解決方案是停止視頻,然後加載其他視圖控制器,以便視頻不會在後臺播放。
我想到的另一個解決方案是在播放完1秒前播放視頻,以便使用movieFinishedCallback方法發佈視頻。我不知道如何能夠將視頻「快進」到那一點。我是新來的Objective-C,我不知道什麼是aNotification參數,否則我只是用適當的參數調用該方法。
讓我告訴你,我得到的錯誤: