Video as launch screen in IOS Objective C. Any help appreciated.
Moorthy You can use AVPlayer and AVPlayerViewController help for Achieving this.
I will Explain you in detail the process of doing this trick.
Step One Add following framework in your Xcode project and import them in on your Appdelegate.
Step Two Add following piece of code in your Appdelegate didFinishLaunchingWithOptions Method
// grab a local URL to our video
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@"myvideo" withExtension:@"mov"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls = false;
controller.view.frame = self.window.frame;
controller.modalPresentationStyle = UIModalPresentationFullScreen;
self.window.rootViewController = controller;
[player play];
// Adding Observer for your video file,
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(videoDidFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
Step Three
After Video Completion you will be take into this place
- (void)videoDidFinish:(id)notification {
AVPlayerItem *p = [notification object];
//do something with player if you want
//Remove Observer
[[NSNotificationCenter defaultCenter] removeObserver:self];
//your initial view can proceed from here
[self ProccedToYourViewController];
}
Some Tips
You can smoothly stop your video play by adding fade in and fade out animation, I will show you how i did for myself
//AvplayerViewController View(Video View).
[self.controller.view setAlpha:1.0f];
[UIView animateWithDuration:2.0f animations:^{
//AvplayerViewController View(Video View) setting to hide.
[self.controller.view setAlpha:0.0f];
//initialview(Your Initial View) that add as window root now
self.window.rootViewController = initialview;
[initialview.view setAlpha:1.0f];
[self.window makeKeyAndVisible];
} completion:nil];
Now You are ready to go. Cheers