Jul 2, 2013

IOS Xcode Create a modal window

Create  a modal window for IOS application in Xcode 

1. Create new view controller either programatically or using a nib file, design it the way you want your modal window to be.
2. Name it youtubeplayer (say).
3. Import its header file into the main view controller (obviously).
4. From the main view controller put the below code into any event. ( clicking of button, or table row selected etc.) 

youtubeplayer *yt = [[youtubeplayer alloc]  initWithNibName:@"youtubeplayer" bundle:[NSBundle mainBundle]];    yt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;    yt.modalPresentationStyle = UIModalPresentationFormSheet;    [self presentViewController:yt animated:YES completion:^{        NSLog(@"this is calleed");    }];    CGRect r = CGRectMake(self.view.bounds.size.width/2 - 350,                          self.view.bounds.size.height/2 - 200,                          700, 400);    r = [self.view convertRect:r toView:yt.view.superview.superview];    yt.view.superview.frame = r;

Also now you will need a button on the modal window opened to close it.
simply create a button or what ever element you are comfortable with and put in the following code in it.

- (IBAction)closeModal:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

that's it Now you are good to go.


If need any help You can ask in comments.

Happy Coding :)

Jul 1, 2013

Retrive the cover images of videos from YouTube


Retrive the cover images of videos from YouTube

Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg2.jpg3.jpg) is:



http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

For the high quality version of the thumbnail use a url similar to this:










http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using a url similar to the HQ:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the maximum resolution version of the thumbnail use a url similar to this:
(if it exists for certain videos youtube does not have a heigh resolution cover pic) .

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above urls are available over https too. Just change http to https in any of the above urls.
Alternatively, you can use the YouTube API to get thumbnail images.