ビデオをダウンロードしてディレクトリに保存し、ユーザーが後でそのファイルを再生できるようにします。
これは、ネットワークの変動によりダウンロードが停止して再開した場合など、すべての場合にうまく機能します。ただし、ファイルが完全にダウンロードされても、MPMoviePlayerViewControllerで再生されない場合があります。
ASIHTTPRequestを使用して、バックグラウンドでビデオファイルをダウンロードしています。
観察:ダウンロード中の可能性があり、ネットワークが時々変動し、ファイルが破損している可能性があります。
質問:ダウンロードしたファイルが破損していることをどうやって知ることができますか?(MPMoviePlayerViewControll経由)
助言がありますか?以下は再生するコードです:
@ACB ...私はあなたのコードを使用しましたが、それは常にelse状態になります:
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];
}