thumbnailImageAtTime:timeOption 已弃用:首先在 iOS 7 中弃用

Posted

技术标签:

【中文标题】thumbnailImageAtTime:timeOption 已弃用:首先在 iOS 7 中弃用【英文标题】:thumbnailImageAtTime:timeOption is deprecated: first deprecated in iOS 7 【发布时间】:2014-01-01 13:46:27 【问题描述】:

我有以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"]) 
    [self performSegueWithIdentifier:@"showImage" sender:self];

 else 

    // File type is video
    PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
    NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
    self.moviePlayer.contentURL = fileUrl;
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];

    // Add it to the view controller so we can see it
    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer setFullscreen:YES animated:YES];

上面写着:

[self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];

它给了我错误:

thumbnailImageAtTime:timeOption: 已弃用:首先在 ios 7.0 中弃用

如果有人能帮助解决这个问题,我们将不胜感激。 谢谢!

【问题讨论】:

thumbnailImageAtTime: now deprecated - What's the alternative?的可能重复 【参考方案1】:

请在此处查看我对同一问题的回答ThumbnailImageAtTime Deprecated - What's the alternative

AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:partOneUrl options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];
[_firstImage setImage:one];
_firstImage.contentMode = UIViewContentModeScaleAspectFit;

在头文件中,请导入

#import <AVFoundation/AVFoundation.h>

它运行完美,我已经能够从 viewDidLoad 调用它,这比从 viewDidAppear 调用已弃用的 thumbNailImageAtTime: 更快。

希望这可以帮助遇到同样问题的其他人。

【讨论】:

【参考方案2】:
AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:partOneUrl options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];
[_firstImage setImage:one];
_firstImage.contentMode = UIViewContentModeScaleAspectFit;

添加AVFoundationCoreMedia框架

#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>

【讨论】:

我对时间变量感到困惑,如何在视频中获得 1 秒内的图像,以及如何获得 2 秒内的图像?

以上是关于thumbnailImageAtTime:timeOption 已弃用:首先在 iOS 7 中弃用的主要内容,如果未能解决你的问题,请参考以下文章