好的,在iOS中模拟启动画面的选项非常有限。我们所能做的就是等待应用程序完全加载,然后创建媒体播放器并在其中加载视频。
我使用以下代码来实现它:
-(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 ...>
}
我的视频只有1MB,但是这段代码却展示的与我想要的不同:
- 首先,用户可以看到静态闪屏几秒钟。
- 然后黑屏出现了1到2秒。我认为这是因为媒体播放器被加载了。
- 视频开始播放。
- 主界面加载。
正如您所理解的那样,我不喜欢黑屏暂停-它看起来很丑陋。
据我在控制台日志中看到的,问题在于媒体播放器等待主视图控制器完全加载。
关于主视图的几句话:我正在为iPad编写一个应用程序,主视图由多个带有多个图像的子视图组成。主视图中的每个图像和每个子视图都通过ASIHTTPRequest库从Internet Web服务加载一些数据。
我认为媒体播放器正在等待所有初始连接完成,然后才开始播放视频...
我怎么才能在主视图加载之前强制播放视频?或者我可以延迟加载主XIB吗?