我正在下載視頻並將其保存在某個目錄中,以便用戶隨後可以播放該文件。如果視頻文件損壞,MPMoviePlayerViewController會返回錯誤嗎?
它適用於所有情況下,如下載停止並由於某種網絡波動而再次恢復。但有時文件完全下載,但不能在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];
}
感謝dilip。我會檢查出來的。 –
它完美無瑕。謝謝迪利普 –