我正在使用下一个片段同步加载值,因此加载 = NO 永远不会触发。
我对 AVAssetExportSession exportAsynchronously 也有同样的问题。
这一切都不仅仅在设备上工作。

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:URL options:options];

NSArray *keys = [NSArray arrayWithObjects:@"duration", @"tracks", nil];

__block bool loading = YES;

[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^(void) {
            loading = NO;
}];

while (loading)[[NSRunLoop currentRunLoop] runUntilDate:[[NSDate date] dateByAddingTimeInterval:0.5]];

请帮忙!我的大脑在融化。

最佳答案

这是我使用的代码:

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"intro" ofType:@"m4v"]];

    self.asset = [[AVURLAsset alloc] initWithURL:url options:nil];
    NSString *tracksKey = @"tracks";

    [self.asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:^{
// Other code here for AVPlayer
}];

我不使用任何选项或任何这种性质的东西。我确定您已经看过 Apple 的文档示例:

http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html

10-05 20:23