在iOS应用程序中模拟启动视频 [英] Emulating splash video in iOS application

查看:124
本文介绍了在iOS应用程序中模拟启动视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在iOS中模拟启动视频的选项很少。我们所能做的就是等到应用程序完全加载,然后创建Media Player并在其中加载视频。

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 ...>

}

我的视频只有1 MB。但是这段代码做了一些不同的事情,我希望看到:

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


  1. 首先,用户可以看到静态启动画面几秒钟;

  2. 然后出现黑屏1或2秒。我认为这是因为媒体播放器已加载。

  3. 视频开始播放。

  4. 主界面加载。

  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.

关于主视图的几句话:我正在编写一个iPad的应用程序和主视图包含多个具有多个图像的子视图。主视图中的每个图像和每个子视图都通过ASIHTTPRequest lib从Internet Web服务加载一些数据。

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.

我认为Media Player正在等待所有初始连接完成,然后才开始它正在启动视频...

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

如何在加载主视图之前强制播放视频?或者也许我可以延迟加载主XIB?

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

推荐答案

你无法摆脱静态启动图像。虽然它显示,操作系统正在加载应用程序并实例化东西,直到它准备好调用你的UIApplicationDelegate。所以你所能做的就是使用不闪光(黑屏几秒钟)或者让你的电影完全按照显示的闪屏开始,这样看起来静态图像会突然变形。

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.

要在电影加载时摆脱黑屏,你可以尝试让播放器透明并在显示启动图像的播放器后面有一个UIImageView。行为将是:

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:


  • 显示启动画面(静态图像)。

  • 应用程序是加载。你看到了UIImageView,也显示了启动画面。最重要的是透明电影播放器​​。

  • 电影播放器​​终于加载了移动并开始播放。

至少在理论上,这应该会导致静态图像突然开始动画效果。

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.

关于在UIImageView中显示启动画面:遗憾的是,您必须测试界面旋转并手动加载图像,无法查询显示的启动画面。如果你只支持一个界面方向(再次,许多游戏都这样做),你当然没有这个问题。

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.

这篇关于在iOS应用程序中模拟启动视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆