iphone MPMoviePlayerViewController handling network problems (black screen) [duplicate]
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.
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];
}
精彩评论