Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

iphone - Emulating splash video in iOS application

OK, there are very few options to emulate the splash video in iOS. All we can do is wait till application is fully loaded and then create Media Player and load video in it.

I implemented it with following code:

-(void) moviePlayBackDidFinish:(NSNotification*)notification
{
    NSLog(@"Intro video stopped");
    [mMoviePlayer release];
}

- (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 = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];
    [mMovieURL release];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:mMoviePlayer];

    mMoviePlayer.controlStyle = MPMovieControlStyleNone;
    [mMoviePlayer.backgroundView addSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Splash/background.png"]] autorelease]];
    mMoviePlayer.scalingMode = MPMovieScalingModeFill;

    [window addSubview:mMoviePlayer.view];
    [mMoviePlayer setFullscreen:YES animated:NO];

    [window makeKeyAndVisible];
    [mMoviePlayer play];

<... other stuff ...>

}

My video is only 1 MB. But this code do something different then I'd like to see:

  1. First of all user can see a static splash screen for a few seconds;
  2. Then a black screen appears for 1 or 2 seconds. I think this is happening because the media player is loaded.
  3. Video start playing.
  4. Main interface loads.

As you understand I don't like the pause with black screen - it looks ugly.

As far as I can see in my Console log the problem is that mediaplayer is waiting till the main view controller is fully loaded.

Few words about main view: i'm writing an application for iPad and the main view consists of several subviews with multiple images. Every image and every subview in main view loads some data from Internet Web service via ASIHTTPRequest lib.

I think that Media Player is waiting for all initial connections to finish and only then it's starting the video...

How can I force the video to play before main view is loaded? Or maybe I can delay the loading of main XIB?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...