Allen Allen - 2 years ago 164
Swift Question

How to Play a mp4 Video on the launch screen when the app loads Xcode SWIFT

Hey I have a Mp4 video that i won't to put on the launch screen. Like who when on image loads on the launch screen but now just a video. And i do know how to put a image on the launch screen but not a video any help?

Answer Source

You can't put a video on the launch screen, but can start a video as soon as the apple starts. Visually, the effect can be undistinguishable.

Just add the video play call on the viewDidLoad method of your first view controller, and place in some control not to force the user to view it all the times the app is run. Otherwise your users will get annoyed soon.

Yom might want to adapt the first photogram of the video to your launch screen, and provide different videos for several device resolutions. Keep in mind that the various video sizes of supported by the various mobile apple devices don't exactly always match the display size of each devices.

Your mileage may vary, you will need to "rotate" your videos in such a way that it appears to be "vertical" when played in horizontal.


- (void) play{
NSString *videoName=@"video320";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        CGFloat height =self.view.frame.size.height;

        //test retina display
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
            // RETINA DISPLAY - you may need to add check for @3x resolutions

        if (height > 460.0){
    } else {
        self.view.backgroundColor=[UIColor blackColor];
        NSString *urlString = [[NSBundle mainBundle]     pathForResource:videoName ofType:@"mp4"];

    NSURL *url = [NSURL fileURLWithPath:urlString];
    if (self.videoPlayer != nil)
        [self.videoPlayer stop];
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

[self.videoPlayer setScalingMode:MPMovieScalingModeAspectFill];
[self.videoPlayer setShouldAutoplay:YES];
[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
for(UIView* subV in self.videoPlayer.view.subviews) {
    subV.backgroundColor = [UIColor clearColor];
[self.tabBarController.view addSubview:self.videoPlayer.view];
[self.navigationController.view addSubview:self.videoPlayer.view];
[self.videoPlayer play];


- (void) terminateVideo:(id)sender{
     [self.videoPlayer.view removeFromSuperview];
     self.videoPlayer =nil;
     self.view.backgroundColor=[UIColor darkGrayColor];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download