AVFoundation для воспроизведения видео петли

Мне нужно бесконечно воспроизводить видео (перезапускать видео, когда оно заканчивается) в моем приложении OpenGL. Для этого яЯ пытаюсь использовать AV фундамент. Я создал AVAssetReader и AVAssetReaderTrackOutput и использую метод copyNextSampleBuffer, чтобы получить CMSampleBufferRef и создать текстуру OpenGL для каждого кадра.

    NSString *path = [[NSBundle mainBundle] pathForResource:videoFileName ofType:type];
    _url = [NSURL fileURLWithPath:path];

    //Create the AVAsset 
    _asset = [AVURLAsset assetWithURL:_url];

    //Get the asset AVAssetTrack
    NSArray *arrayAssetTrack = [_asset tracksWithMediaType:AVMediaTypeVideo];
    _assetTrackVideo = [arrayAssetTrack objectAtIndex:0];

    //create the AVAssetReaderTrackOutput
    NSDictionary *dictCompressionProperty = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id) kCVPixelBufferPixelFormatTypeKey];
    _trackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:_assetTrackVideo outputSettings:dictCompressionProperty];

    //Create the AVAssetReader
    NSError *error;
    _assetReader = [[AVAssetReader alloc] initWithAsset:_asset error:&error];
    if(error){
        NSLog(@"error in AssetReader %@", error);
    }
    [_assetReader addOutput:_trackOutput];
    //_assetReader.timeRange = CMTimeRangeMake(kCMTimeZero, _asset.duration);

    //Asset reading start reading
    [_assetReader startReading];

И в методе -update моего GLKViewController я вызываю следующее:

if (_assetReader.status == AVAssetReaderStatusReading){
    if (_trackOutput) {
        CMSampleBufferRef sampleBuffer = [_trackOutput copyNextSampleBuffer];
        [self createNewTextureVideoFromOutputSampleBuffer:sampleBuffer]; //create the new texture
    }
}else if (_assetReader.status == AVAssetReaderStatusCompleted) {
    NSLog(@"restart");
    [_assetReader startReading];
}

Все работает нормально, пока AVAssetReader не будет в состоянии чтения, но когда он закончил чтение, и я попытался перезапустить AVAssetReading с новым вызовом [_assetReader startReading], приложение вылетает без вывода. Что я'я делаю неправильно? Правильно ли перезапустить AVAssetReading, когда он завершит чтение?

Ответы на вопрос(2)

Ваш ответ на вопрос