gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:07:48 24 4
gpt4 key购买 nike

嘿,我使用 MPMoviePlayerViewController 来显示视频。我不知道如何处理网络问题。我想在出错时关闭 MPMoviePlayerViewController Controller 。 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];
}

请告诉我如何处理网络问题。另请注意,该视频始终处于全屏状态。

最佳答案

为什么你创建VideoViewController有什么特殊原因?如果您想自定义某些东西,那么您可以在不创建它的情况下完成所有操作,这也没关系。另一件事是,对于这两个通知,您都注册了“movieDidLoad”此方法,这将关闭您的 View 。当视频准备好播放时,您的 View 将因您注册了“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];

}

关于iphone MPMoviePlayerViewController 处理网络问题(黑屏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5523297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com