我正在下载视频并将其保存在某个目录中,以便用户之后可以播放该文件。
它适用于所有情况,例如由于某些网络波动而停止下载并再次恢复。但有时文件完全下载但没有在 MPMoviePlayerViewController 中播放。
我正在使用 ASIHTTPRequest 在后台下载视频文件。
观察:可能是在下载过程中,网络有时会波动,文件可能已经损坏。
问题:我怎样才能知道下载的文件已损坏?(通过 MPMoviePlayerViewControll)
有什么建议么?下面是玩的代码:
@ACB ...我使用了您的代码,但它总是处于其他状态:
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];
}