iphone MPMoviePlayerViewController 处理网络问题(黑屏)
嘿,我使用 MPMoviePlayerViewController 来显示视频。我不知道如何处理网络问题。我想在出错时关闭 MPMoviePlayerViewController 控制器。 missMoviePlayerViewControllerAnimated 方法仅在第一次有效,第二次我得到黑屏。
示例代码:
// 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];
}
请告诉我如何处理网络问题。另请注意,该视频始终为全屏。
Hey, I use MPMoviePlayerViewController to display video. I don't know how to handle network problems. I would like to dismiss the MPMoviePlayerViewController controller on error. The dismissMoviePlayerViewControllerAnimated method works only the first time, the second time I get black screen.
Example code:
// 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];
}
Please tell me how to handle network problems. Note also, that video is always in fullscreen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么你创建VideoViewController有什么特殊原因?如果您想自定义某些东西,那么您可以在不创建它的情况下完成所有操作,这也没关系。另一件事是,对于这两个通知,您都注册了“movieDidLoad”此方法,这将关闭您的视图。当视频准备好播放时,您的视图将因您注册了“MPMoviePlayerContentPreloadDidFinishNotification”的此方法而被关闭。此链接将为您提供更多帮助:
}
Why you have created VideoViewController any special reason? You can do that all things without creating that if you want to customize something than it's okay. Other thing is that for both notification you have registered "movieDidLoad " this method and this will dismiss your view.When video will be ready to play then you'r view will be dismiss due to this method you have registered for the " MPMoviePlayerContentPreloadDidFinishNotification ". This link will help you more:
}