我正在使用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];
}在这种情况下播放视频有什么问题?任何答案和建议都将是有价值的。
发布于 2012-06-26 15:13:04
您的方法可能会出现许多关键错误。
对我来说,你似乎在尝试做一些不太有用的事情。如果你能编辑这个问题来解释你到底想做什么,我们也许能提供更多帮助。否则,问题就是要求我们解决一个糟糕的设计中的实现错误。你会得到一个不好的答案(就像这个),你不会接受,你的接受率会下降,你不会得到未来的答案。我希望这对你有帮助,我知道一开始很难,但试着解释一下:
对于这个问题,您似乎错过了第一步。
https://stackoverflow.com/questions/11201315
复制相似问题