好的..我遇到了您的问题,问题是您没有收到除 MPMovieLoadStatePlayable 之外的加载状态通知。所以在这里你可以做的是......就像下面......
在 viewdidload 中的通知下方写下
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
在 ViewDidLoad 中定义后,实现如下功能......
- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
//your code....
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
NSString *reason = @"Unknown";
switch (finishReason)
{
case MPMovieFinishReasonPlaybackEnded:
reason = @"Playback Ended";
break;
case MPMovieFinishReasonPlaybackError:
reason = @"Playback Error";
break;
case MPMovieFinishReasonUserExited:
reason = @"User Exited";
break;
}
NSLog(@"Finish Reason: %@%@", reason, error ? [@"\n" stringByAppendingString:[error description]] : @"");
}
- (void) moviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSString *playbackState = @"Unknown";
switch (moviePlayerController.playbackState)
{
case MPMoviePlaybackStateStopped:
playbackState = @"Stopped";
break;
case MPMoviePlaybackStatePlaying:
playbackState = @"Playing";
break;
case MPMoviePlaybackStatePaused:
playbackState = @"Paused";
break;
case MPMoviePlaybackStateInterrupted:
playbackState = @"Interrupted";
break;
case MPMoviePlaybackStateSeekingForward:
playbackState = @"Seeking Forward";
break;
case MPMoviePlaybackStateSeekingBackward:
playbackState = @"Seeking Backward";
break;
}
NSLog(@"Playback State: %@", playbackState);
}
- (void) moviePlayerLoadStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSMutableString *loadState = [NSMutableString new];
MPMovieLoadState state = moviePlayerController.loadState;
if (state & MPMovieLoadStatePlayable)
[loadState appendString:@" | Playable"];
if (state & MPMovieLoadStatePlaythroughOK)
[loadState appendString:@" | Playthrough OK"];
if (state & MPMovieLoadStateStalled)
[loadState appendString:@" | Stalled"];
NSLog(@"Load State: %@", loadState.length > 0 ? [loadState substringFromIndex:3] : @"N/A");
}
让我知道它是否有效!
快乐编码!!!!