嘿,我使用MPMoviePlayerViewController来显示视频。我不知道如何处理网络问题。我想在错误时解雇MPMoviePlayerViewController控制器。 dismissMoviePlayerViewControllerAnimated方法只在第一次工作,第二次我得到黑屏。
示例代码:
// VideoViewController.h
#import <MediaPlayer/MediaPlayer.h>
@interface VideoViewController : MPMoviePlayerViewController
{
}
@end
// VideoViewController.m
@implementation VideoViewController
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidLoad:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidLoad:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
-(void)movieDidLoad:(NSNotification*)notification
{
[self dismissMoviePlayerViewControllerAnimated];
}
@end
// XController's function to call it
- (void)showVideoView
{
VideoViewController * controller = [[VideoViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://myvideos.com/movie.m4v"]];
[self presentMoviePlayerViewControllerAnimated:controller];
[controller.moviePlayer play];
[controller release];
}
请告诉我如何处理网络问题。另请注意,视频始终处于全屏状态。
答案 0 :(得分:2)
为什么你有任何特殊原因创建了VideoViewController?你可以做所有事情而不创造它,如果你想定制的东西比没关系。另外一点是,对于这两个通知你已经注册了“movieDidLoad”这个方法,这将解除你的观点。当视频准备好播放时,你的视图将被解雇,因为你注册了“MPMoviePlayerContentPreloadDidFinishNotification”。此链接将为您提供更多帮助:
- (void)playbackFinished:(NSNotification*)notification {
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
NSLog(@"playbackFinished. Reason: Playback Ended");
break;
case MPMovieFinishReasonPlaybackError:
NSLog(@"playbackFinished. Reason: Playback Error");
break;
case MPMovieFinishReasonUserExited:
NSLog(@"playbackFinished. Reason: User Exited");
break;
default:
break;
}
[self.movieController setFullscreen:NO animated:YES];
}