Cool utility method to display HH:MM:SS from seconds

When I was developing video recording application, I had to display the time in HH:MM:SS format.
I wrote a utility method which does the same. It takes seconds as input and returns a NSString. Hope this helps iOS community 🙂
NSString * formatHHMMSSStringFromSeconds(int seconds)
{
    NSString *timeString = @"";
    int minutes = seconds / 60;
    seconds = seconds % 60;
    int hours = 0;
    if(minutes > 60)
    {
        hours = minutes / 60;
        minutes = minutes % 60;
    }
    timeString = [timeString stringByAppendingFormat:@"%02d:%02d:%02d",hours,minutes, seconds];
    return timeString;
}
Advertisements

svnX FileMerge does not work with XCode 4.3 upgrade

Many of us who upgraded their XCode to 4.3 must be facing an issue with FileMerge application which is part of svnX. After the XCode 4,3 upgrade, FileMerge application location has been changed. This is why it fails to launch from svnX.

You can fix this running the following command on terminal.
sudo /usr/bin/xcode-select-switch/Applications/Xcode.app/Contents/Developer

Also, you can launch the FileMerge directly from Xcode.
Xcode -> Open Developer Tool -> FileMerge.

The application binary can be found here:
/Applications/Xcode.app/Contents/Applications/FileMerge.app.

 

UIImage From Movie File

Simple utility method to create a image from video file. Specify the size of the image and the time interval.

UIImage *getImageFromMovieAtTime(AVURLAsset *videoAsset, CGSize imageSize,CMTime frameTime)
{
NSError *error =nil;
CMTime actualTime;


AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:videoAsset];
imageGenerator.appliesPreferredTrackTransform = YES;
imageGenerator.maximumSize = imageSize;
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:frameTime actualTime:&actualTime error:&error];
UIImage *movImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

if(error || movImage == nil)
{
DEBUGLOG(@"Error: %@",error);
}
DEBUGLOG(@"imagesize: %@",NSStringFromCGSize(movImage.size));

return movImage;
}

Usage:

    UIImage *videoFrame = getImageFromMovieAtTime(videoAsset, CGSizeMake(width, height),kCMTimeZero);