AVURLAsset loadValuesAsynchronouslyForKeys: completeHandler: never fires on the device

I use the following snippet for loadValues ​​synchronously, so loading = NO never works. And I have the same problem with AVAssetExportSession exportAsynchronously. All this does not work only on the device.

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

Please, help! My brain is melting.

+4
source share
1 answer

Here is the code I'm using:

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

I do not use any options or anything like that. I'm sure you saw an example of Apple documentation:

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

0
source

All Articles