Skip to content

Instantly share code, notes, and snippets.

@youngshook
Forked from mindbrix/drawTimecodeUsingGCD.m
Last active August 29, 2015 14:07
Show Gist options
  • Save youngshook/8a0e1f58f19839437f32 to your computer and use it in GitHub Desktop.
Save youngshook/8a0e1f58f19839437f32 to your computer and use it in GitHub Desktop.
-(void)drawTimecodeUsingGCD
{
if( dispatch_semaphore_wait( _timecodeSemaphore, DISPATCH_TIME_NOW ) != 0 )
{
return;
}
dispatch_async( _timecodeQueue, ^()
{
float fontSize = ceilf( self.scrubberSize * 0.425f );
UIFont *font = [ UIFont fontWithName:@"Courier" size:fontSize ];
CGSize labelSize = [ _avPlayerView.timecode sizeWithFont:font ];
UIGraphicsBeginImageContextWithOptions( labelSize, NO, [ UIScreen mainScreen ].scale );
[[ UIColor blackColor ] set ];
[ _avPlayerView.timecode drawAtPoint:CGPointZero withFont:font ];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async( dispatch_get_main_queue(), ^()
{
self.timecodeImageView.image = image;
self.timecodeImageView.frame = CGRectMake( 0.0f, 0.0f, labelSize.width + self.thumbnailPadding, labelSize.height + self.thumbnailPadding );
[ self.timecodeImageView centreHorizontally ];
self.timecodeImageView.hidden = self.timecodeHidden;
dispatch_semaphore_signal( _timecodeSemaphore );
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment