iphone MPMoviePlayerViewController 处理网络问题(黑屏)

发布于 2024-10-30 00:20:25 字数 1219 浏览 2 评论 0原文

嘿,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2024-11-06 00:20:25

为什么你创建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];

}

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:

- (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];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文