Can MPMoviePlayerViewController return an error if the video file is damaged?

I upload the video and save it in some directory so that the user can then play this file.

It works well in all cases, for example, when the download stops and resumes again due to some network fluctuations. But sometimes the file is fully loaded, but not played in MPMoviePlayerViewController.

I am using ASIHTTPRequest to download video files in the background.

Observation. It may be that the network hesitates several times during startup, and the file may be corrupted.

Question. How to find out if the downloaded file is damaged? (via MPMoviePlayerViewControll)

Any suggestions? Below is the code:

@ACB ... I used your code, but it always goes into a different state:

playerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; player = [playerViewController moviePlayer]; player.movieSourceType = MPMovieSourceTypeFile; [player prepareToPlay]; if(player.loadState == MPMovieLoadStatePlayable) { playerViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentMoviePlayerViewControllerAnimated:playerViewController]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerInterruptByUser:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:playerViewController.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController.moviePlayer]; //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerFinished:) name:UIApplicationDidEnterBackgroundNotification object:playerViewController.moviePlayer]; [player play]; } else { corruptVideoAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Corrupt Video", nil) message:NSLocalizedString(@"This video is corrupted due to some network error. We suggest you to download again. Do you want to download it again?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil),nil]; [corruptVideoAlert show]; [corruptVideoAlert release]; } 
+4
source share
3 answers

I found a similar problem and I solved this problem. Try entering the code:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlayingErrorNotification:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController.moviePlayer]; -(void)playerPlayingErrorNotification:(NSNotification*)notif { NSNumber* reason = [[notif userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]; switch ([reason intValue]) { case MPMovieFinishReasonPlaybackEnded: NSLog(@"Playback Ended"); break; case MPMovieFinishReasonPlaybackError: NSLog(@"Playback Error"); [self performSelector:@selector(CorruptVideoAlertView) withObject:nil afterDelay:1.0]; break; case MPMovieFinishReasonUserExited: NSLog(@"User Exited"); break; default: break; } } 

Accept it if it works for you too. A good day.

+3
source

Use

 if(moviePlayer.loadState == MPMovieLoadStatePlayable) 

and check if it is reproducible. You can use MPMoviePlayerLoadStateDidChangeNotification if necessary. Check your Apple documentation for more details .

You can try this as follows:

 playerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; player = [playerViewController moviePlayer]; player.movieSourceType = MPMovieSourceTypeFile; [player prepareToPlay]; playerViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentMoviePlayerViewControllerAnimated:playerViewController]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerInterruptByUser:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:playerViewController.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerViewController.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:playerViewController.moviePlayer]; //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerFinished:) name:UIApplicationDidEnterBackgroundNotification object:playerViewController.moviePlayer]; 

In loadStateChanged: do the following:

 if(player.loadState == MPMovieLoadStatePlayable) { [player play]; } else { corruptVideoAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Corrupt Video", nil) message:NSLocalizedString(@"This video is corrupted due to some network error. We suggest you to download again. Do you want to download it again?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil),nil]; [corruptVideoAlert show]; [corruptVideoAlert release]; } 
+2
source

In my script, I ended up recording the expected length of the content of the incoming video and made sure that the file size was the same as when you were trying to play the video.

In that sense, it was faster for me to decide if I even needed to play the video. If the file sizes do not match, I just restart the download.

0
source

All Articles