简体   繁体   English

thumbnailImageAtTime:不推荐使用timeOption:首先在iOS 7中弃用

[英]thumbnailImageAtTime:timeOption is deprecated: first deprecated in iOS 7

I have the code below: 我有以下代码:

- (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];
}

On the line that says: 在线上说:

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

it gives me the error: 它给了我错误:

thumbnailImageAtTime:timeOption: is deprecated: first deprecated in iOS 7.0 thumbnailImageAtTime:timeOption:不推荐使用:首先在iOS 7.0中弃用

If anyone could help fix this problem, it would be appreciated. 如果有人可以帮助解决这个问题,我们将不胜感激。 Thank you! 谢谢!

Please see my answer to this same issue here ThumbnailImageAtTime Deprecated - What's the alternative 请在此处查看我对此问题的回答ThumbnailImageAtTime已弃用 - 有什么替代方案

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;

Within header file, please import 在头文件中,请导入

#import <AVFoundation/AVFoundation.h>

It works perfect and I've been able to call it from viewDidLoad, which was quicker than calling the deprecated thumbNailImageAtTime: from the viewDidAppear. 它工作得很完美,我已经能够从viewDidLoad调用它,这比从viewDidAppear调用已弃用的thumbNailImageAtTime更快。

Hope this helps anyone else who had the same problem. 希望这可以帮助其他遇到同样问题的人。

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;

Add AVFoundation and CoreMedia framework 添加AVFoundationCoreMedia框架

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM