iOS でビデオと画像のキャッシュを使用しています。画像キャッシュを実装しました。同じキャッシュにビデオを保存したいのですが、画像とビデオをキャッシュに保存するための次のコードがあります。
-(void)cacheFromURL:(Food*)foodForUrl
{
AppDelegate *app=[[UIApplication sharedApplication]delegate];
[app.imageCache setCountLimit:50];
NSURL *imageUrl=[NSURL URLWithString:foodForUrl.image];
NSURL *videoUrl=[NSURL URLWithString:foodForUrl.video];
UIImage* newImage = [cache objectForKey:imageUrl.description];
if( !newImage )
{
NSError *err = nil;
if(imageUrl!=Nil)
{
newImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl options:0 error:&err]];
}
if(videoUrl!=Nil)
{
moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:videoUrl];
[app.imageCache setObject:moviePlayer forKey:videoUrl.description];
NSLog(@"video caching....%@",videoUrl.description);
}
if( newImage )
{
[app.imageCache setObject:newImage forKey:imageUrl.description];
NSLog(@"caching....");
}
else
{
}
}
}
キャッシュから取得するための次のコードがあります。画像では機能していますが、ビデオでは機能していません:
- (IBAction)playButton:(id)sender
{
AppDelegate *app=[[UIApplication sharedApplication]delegate];
NSURL *url=[[NSURL alloc]initWithString:food.video];
NSLog(@"cached for:%@",url.description);
moviePlayerController=[[MPMoviePlayerController alloc]init];
// moviePlayerController=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:food.video]];
moviePlayerController=[app.imageCache objectForKey:url.description];
moviePlayerController.scalingMode=MPMovieScalingModeAspectFill;
moviePlayerController.view.frame=CGRectMake(320,200, 320,200);
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
}
この場合、ビデオを再生する際の問題は何ですか? どんな答えや提案も貴重です