我可能说的标题不太好,也许更正确地说我的NSNotification在播放完电影后并没有消除我的电影视线。我发现其他人有此问题,但没有解决方案,似乎我正在运行的iOS 6可能有问题。
视频播放完后,您需要按“完成”以关闭,但我希望它自动关闭,因为一旦解决了该问题,我将使用MPMovieControlStyleNone。这是我的代码,其中未使用的部分被删除:
`
#import "MovieViewController.h"
@interface MovieViewController ()
@end
@implementation MovieViewController
@synthesize moviePlayer = _moviePlayer;
- (IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"TestMovie" ofType:@"mov"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
@end`
最佳答案
也有这个问题
修复moviePlayBackDidFinish
只需添加
player.fullscreen = NO;
从 super View 中删除 View 之前