我一整天都在努力,但由于某种原因,在IOS6上我遇到了很多与MPMoviePlayerController有关的问题,似乎人们遇到了问题,但与我的问题不太相似:
电影完成后,电影会加载并播放正常。我可以循环播放电影。当我尝试关闭并删除电影时会出现问题:
如果我将控件添加到电影本身并点击“完成”按钮,那么电影只会暂停和播放。永远不会关闭!
任何提示/想法?
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackLoaded:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:_moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:kMovieOverlayViewTapped
object:nil];
[self.view addSubview:_moviePlayerController.view];
_moviePlayerController.fullscreen = YES;
-
现在正在播放加载:
- (void)moviePlaybackLoaded:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:_moviePlayerController];
_moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
_moviePlayerController.controlStyle = MPMovieControlStyleDefault;
[_moviePlayerController prepareToPlay];
[_moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
[_moviePlayerController play];
}
现在删除视频:
- (void)moviePlaybackComplete:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayerController];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerDidExitFullscreenNotification
object:_moviePlayerController];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kMovieOverlayViewTapped
object:nil];
[_moviePlayerController stop];
[_moviePlayerController.view removeFromSuperview];
_moviePlayerController = nil;