AVURLAsset refuses to load video AVURLAsset refuses to load video ios ios

AVURLAsset refuses to load video


Solved. The trick: use fileURLWithPath:, not URLWithString:. Apparently the difference is really, really significant.


If anyone is still having issues with this even after using fileURLWithPath, try requesting NSTimeIntervals in the time array if you are using int(s).

This does not work:

    NSMutableArray *playbackTimes = [NSMutableArray array];    for (int i = 0; i <= 10; i ++) {        [playbackTimes addObject:@(i)];    }    [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];

This works:

    NSMutableArray *playbackTimes = [NSMutableArray array];    for (int i = 0; i <= 10; i ++) {         [playbackTimes addObject:@((NSTimeInterval)i)];     }     [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];


If you are using -[NSURL fileURLWithPath:] to create the URL and still get the same error.

Check the AVURLAssetReferenceRestrictionsKey, Your local m3u8 may failed to play if it contains remote resource.

Set the value to @(AVAssetReferenceRestrictionForbidNone) should solve the problem.