AVURLAsset se niega a cargar vídeo


Estoy tratando de cargar un archivo de vídeo en mi aplicación para iPad como un AVURLAsset, utilizando las cosas de carga asíncrona para esperar a que esté listo. El problema es que, cuando lo corro, recibo un mensaje de error de "falla" completamente genérico con el que no tengo idea de qué hacer. El video funciona si se lo doy a un MPMoviePlayerController, pero AVURLAsset parece negarse a tener nada que ver con él.

Código:

asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:[docPath stringByAppendingPathComponent:@"video.mov"]] options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self composeIfReady];
    });
}];

...

- (void)composeIfReady
{
    NSError *error = nil;
    if([asset statusOfValueForKey:@"tracks" error:&error] == AVKeyValueStatusFailed)
        NSLog(@"error loading: %@", [error description]);
    if(error == nil)
        NSLog(@"okay awesome");
}

La salida:

error loading: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)" UserInfo=0x1696f0 {NSUnderlyingError=0x169a40 "The operation couldn’t be completed. (OSStatus error -12936.)"}

-11800, por cierto, es el código de error para "error desconocido". Un callejón sin salida. Alguna idea? ¿Hay algo que deba configurar antes de intentar cargar el activo?

Author: Noah Witherspoon, 2010-11-05

3 answers

Resuelto. El truco: usa fileURLWithPath:, no URLWithString:. Aparentemente la diferencia es muy, muy significativa.

 112
Author: Noah Witherspoon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-17 04:12:47

Si alguien sigue teniendo problemas con esto incluso después de usar fileURLWithPath, intente solicitar NSTimeIntervals en la matriz de tiempo si está utilizando int(s).

Esto no funciona:

    NSMutableArray *playbackTimes = [NSMutableArray array];
    for (int i = 0; i <= 10; i ++) {
        [playbackTimes addObject:@(i)];
    }

    [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];

Esto funciona:

    NSMutableArray *playbackTimes = [NSMutableArray array];
    for (int i = 0; i <= 10; i ++) {
         [playbackTimes addObject:@((NSTimeInterval)i)];
     }

     [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];
 6
Author: Edwin Iskandar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-15 15:42:11

Si está utilizando -[NSURL fileURLWithPath:] para crear la URL y aún así obtener el mismo error.

Compruebe el AVURLAssetReferenceRestrictionsKey, Es posible que su m3u8 local no se reproduzca si contiene recursos remotos.

Establecer el valor en @(AVAssetReferenceRestrictionForbidNone) debería resolver el problema.

 5
Author: naituw,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-17 15:32:02