Emulating splash video in iOS application

十年热恋 提交于 2019-11-28 17:39:56
DarkDust

You cannot get rid of the static splash image. While it is shown, the OS is loading the application and instantiating stuff until it is ready to call your UIApplicationDelegate. So all you can do is either use no splash (black screen for a few seconds) or make your movie start exactly with the shown splash screen so it looks like the static image would suddenly animate.

To get rid of the black screen while the movie loads, you can try to make the player transparent and have an UIImageView behind the player that shows the splash image. The behavior would be this:

  • Splash screen is shown (static image).
  • Application is loaded. You see the UIImageView, also showing the splash screen. On top of it is the transparent movie player.
  • Movie player finally has loaded the move and starts playing it.

At least in theory, this should cause the effect that the static image suddenly starts animating.

But if you don't use a splash screen at all (a lot of games do that), then it doesn't matter that the movie player is showing a black screen at first, you wouldn't notice.

Regarding showing the splash screen in an UIImageView: unfortunately, you have to test the interface rotation and load the image manually, there's no way to query which splash screen was shown. If you only support one interface orientation (again, a lot of games do this) you don't have this problem, of course.

There is a better solution now, assuming you are using UIViewControllers.

Instead of using MPMoviePlayerController, use MPMoviePlayerViewController. Here is some sample code, adapted from the question:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    NSURL* mMovieURL;
    NSBundle *bundle = [NSBundle mainBundle];
    if(bundle != nil)
    {
        NSString *moviePath = [bundle pathForResource:@"intro" ofType:@"mp4"];
        if (moviePath)
        {
            mMovieURL = [NSURL fileURLWithPath:moviePath];
            [mMovieURL retain];
        }
    }

    mMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:mMovieURL];
    [mMovieURL release];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:mMoviePlayer.moviePlayer];
    mMoviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
    [mMoviePlayer.moviePlayer.backgroundView  addSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SplashCopy.png"]] autorelease]];
    mMoviePlayer.moviePlayer.scalingMode = MPMovieScalingModeFill;
    [window.rootViewController.view addSubview:mMoviePlayer.moviePlayer.view];
    [mMoviePlayer.moviePlayer setFullscreen:YES animated:NO];
    [mMoviePlayer.moviePlayer play];

}

Emulating splash video in iOS application this code for swift4.0

        var mMovieURL: URL?
        let bundle = Bundle.main
        if bundle != nil {
            let moviePath: String? = bundle.path(forResource: "intro", ofType: "mp4")
            if moviePath != nil {
                mMovieURL = URL(fileURLWithPath: moviePath ?? "")

            }
        }
        mMoviePlayer = MPMoviePlayerController(contentURL: mMovieURL!)
        NotificationCenter.default.addObserver(self, selector: #selector(self.moviePlayBackDidFinish), name: .MPMoviePlayerPlaybackDidFinish, object: mMoviePlayer)
        mMoviePlayer.controlStyle = .none
        mMoviePlayer.backgroundView.addSubview(UIImageView(image: UIImage(named: "Splash.png")))
        mMoviePlayer.scalingMode = .fill
        window?.addSubview(mMoviePlayer.view)
        // window?.rootViewController?.view.addSubview(mMoviePlayer.view)
        mMoviePlayer.setFullscreen(true, animated: false)
        window?.makeKeyAndVisible()
        mMoviePlayer.play()

        return true
     }

     @objc func moviePlayBackDidFinish(_ notification: Notification) {
         mMoviePlayer.view.removeFromSuperview()
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!