0

I am reading a video file and processing it. The code for it is based on the code in this question.

 AVURLAsset * asset = [AVURLAsset URLAssetWithURL:url options:nil];
 [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:
 ^{
     dispatch_async(dispatch_get_main_queue(),
                    ^{
                        AVAssetTrack * videoTrack = nil;
                        NSArray * tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
                        if ([tracks count] == 1)
                        {
                            //some code here

                            [movieReader startReading];

                            while ([movieReader status] == AVAssetReaderStatusReading)
                            {
                             // reading the video code here
                            }
                         }
                      });
   });

I need to update the UI as I process each frame indicating the progress of processing frames. I insert a button on the UI inside the while loop, however, the UI gets updated only when the entire video processing is complete. Infact, any UI update performed in the completion handler block takes place only after the entire processing. Any suggestions on how to do it ?

Community
  • 1
  • 1
Hrishikesh_Pardeshi
  • 995
  • 4
  • 19
  • 45

1 Answers1

1

Your main thread is being blocked by that while loop. What you need to do is schedule a recurring NSTimer (say, every 1/60 seconds) on the run loop of the main thread whose action method calls [movieReader status] and updates the progress.

fumoboy007
  • 5,345
  • 4
  • 32
  • 49