[英]Received memory warning when use MPMoviePlayerController
以缩略图形式从MPMoviePlayerController获取“接收到的内存警告”并且应用程序崩溃了。
我正在使用代码:
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
for (int i = 0; i < pickedVideoAssetDuration; i ++){
UIImage *singleFrameImage = [movie thumbnailImageAtTime:i timeOption:MPMovieTimeOptionExact];
CGSize newSize = CGSizeMake(50, 50);
// checks whether the thumbnails are properly extracted or not
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0f);
[singleFrameImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
NSLog(@"newSize >60 : %@", NSStringFromCGSize(newImage.size));
UIGraphicsEndImageContext();
// checks whether the thumbnails are properly extracted or not
if(newImage)
[durationArray addObject:newImage];
else
NSLog(@"nil thumbnail");
dispatch_async(dispatch_get_main_queue(), ^{
[self designthumbScroll:thumbImageCount];
});
}}
如果有任何帮助将不胜感激:)
通常,将视频加载到内存中非常昂贵。
也许尝试在循环内部添加@autoreleasepool以稍微更快地释放内存:
for (int i = 0; i < pickedVideoAssetDuration; i ++)
{
@autoreleasepool{
// your existing code
}
}
否则,请查看其余代码,并查看当时可以释放的内存。
尝试通过获取缩略图
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newPath = [documentsDirectory stringByAppendingPathComponent:@"YourVideoFileName"];
UIImage * thumbnailImg = [self getThumbNail:newPath];
和方法代码
-(UIImage *)getThumbNail:(NSString *)stringPath
{
NSURL *videoURL = [NSURL fileURLWithPath:stringPath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
return thumbnail;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.