Fixing the video black screen issue in iOS 6

Leave a comment

Hello friends


While trying to work on a project I had an issue of getting black screen with videos

Fixed it with a hack


Find the code below for that

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
switch (self.interfaceOrientation) {
case UIInterfaceOrientationPortraitUpsideDown:
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI)); // 180 degrees
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(0.0));

UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinishImgHot:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

Hope it helps at-least some of you
Cheers :)

Determining UIWebView height based on content

Leave a comment

It is really easy to determine the height of the UIWebView based on content, once you know it ;)

Here is a solution I used. (As seen from StackOverflow)

In a view controller’s viewDidLoad I load some HTML in a webview and when the load is finished run some javascript to return the element height.

- (void)viewDidLoad
[super viewDidLoad];
webview.delegate = self;
[webview loadHTMLString:@"<div id='foo' style='background: red'>The quick brown fox jumped over the lazy dog.</div>" baseURL:nil];

- (void)webViewDidFinishLoad:(UIWebView *)webView
NSString *output = [webview stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"foo\").offsetHeight;"];
NSLog(@"height: %@", output);

Also you may use the following code instead.

NSString *output = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];

Hope this helps somebody

iBooks like library for magazine apps

Leave a comment

Hello friends

So my prime focus in the last few years have been digital magazines.

So here is an awesome library that I am grateful for. It is called AQGridView written by 


You can find the git here.

It is really simple to use.

The three delegate methods, which are similar to a UITableView are

- (NSUInteger) numberOfItemsInGridView: (AQGridView *) aGridView

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index

- (void) gridView: (AQGridView *) gridView didSelectItemAtIndex: (NSUInteger) index

Happy coding!!!

Adding a frame (Watermark) to a video in iOS


Hello Friends

Here is something I stumbled upon while doing a video editing app.
Video editing is a real PITA.
So here is some code to add a frame (Watermark) to a video in iOS

You just need to use a CALayer and AVVideoCompositionCoreAnimationTool.

AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:outputFileURL options:nil];
AVMutableComposition* mixComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

//If you need audio as well add the Asset Track for audio here

[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil];

[compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]];

With just this code you would be able to export the video but we want to add the layer with the watermark first.
Please note that some code may seem redundant but it is necessary for everything to work.
First we create the layer with the watermark image:

UIImage *myImage = [UIImage imageNamed:@"icon.png"];
CALayer *aLayer = [CALayer layer];
aLayer.contents = (id)myImage.CGImage;
aLayer.frame = CGRectMake(5, 25, 57, 57); //Needed for proper display. We are using the app icon (57x57). If you use 0,0 you will not see it
aLayer.opacity = 0.65; //Feel free to alter the alpha here

If you want a text instead of image here is the code

CATextLayer *titleLayer = [CATextLayer layer];
titleLayer.string = @"Text goes here";
titleLayer.font = @"Helvetica";
titleLayer.fontSize = videoSize.height / 6;
//?? titleLayer.shadowOpacity = 0.5;
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height / 6); //You may need to adjust this for proper display

The following code sorts the layer in proper order:

CGSize videoSize = [videoAsset naturalSize];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:aLayer];
[parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED TEXT

Now we are creating the composition and add the instructions to insert the layer:

AVMutableVideoComposition* videoComp = [[AVMutableVideoComposition videoComposition] retain];
videoComp.renderSize = videoSize;
videoComp.frameDuration = CMTimeMake(1, 30);
videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];

/// instruction
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mixComposition duration]);
AVAssetTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
videoComp.instructions = [NSArray arrayWithObject: instruction];

And now we are ready to export:

_assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];//AVAssetExportPresetPassthrough
_assetExport.videoComposition = videoComp;

NSString* videoName = @"";

NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath];

if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;

[strRecordedFilename setString: exportPath];

[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
[_assetExport release];

[audioAsset release];
[videoAsset release];

Hope this helps somebody

Multiple instances of Skype in Mac

Leave a comment

Hello Friends

Today I encountered a new problem @ office.
To login to two Skype accounts on the same User in my iMac with Mac OS X Lion.
After a little search found the following solution

- Open Skype from Applications and login to Account-A
Step 1: Open a Terminal window
Step 2: cd /Applications/­ts/MacOS/
Step 3: sudo ./Skype
Now, login to Account-B
You can see two icons in the dock having separate Skype logins (Account-A and Account-B)

Thanks and Cheers ;)

High Def wallpapers for your Mac

1 Comment

Found a great link to 100 HD wallpapers for your mac on Mac Appstorm

Here are some of them


Find the full list on the above link

Source codes of live apps in Appstore

Leave a comment

Have you ever wanted the sample code of an iPhone Game or app that is live in Appstore.
Credits to Maniacdev for posting these helpful links. You can find the full list there.

I’m just listing ten of which I like

1. CanabaltSource

2. Doom ClassicSource

3. WikipediaSource

4. WordPressSource

5. Wolfenstein 3D Classic PlatinumSource

6. TweejumpSource

7. Task CoachSource

8. Sign+Source

9. pwSafe – Password Safe for iOSSource

10. Last.fmSource

You can find the full list on the above link.
Cheers ;)

Older Entries


Get every new post delivered to your Inbox.