WAS*_*D42 11 iphone splash-screen mpmovieplayercontroller ipad
好的,在iOS中模拟启动视频的选项很少.我们所能做的就是等到应用程序完全加载,然后创建Media Player并在其中加载视频.
我用以下代码实现了它:
-(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 ...>
}
Run Code Online (Sandbox Code Playgroud)
我的视频只有1 MB.但是这段代码做了一些与众不同的事情,我希望看到:
如你所知,我不喜欢黑屏的暂停 - 它看起来很难看.
据我在控制台日志中看到的问题是,媒体播放器正在等待主视图控制器完全加载.
关于主视图的几句话:我正在为iPad编写应用程序,主视图包含多个带有多个图像的子视图.主视图中的每个图像和每个子视图都通过ASIHTTPRequest lib从Internet Web服务加载一些数据.
我认为Media Player正在等待所有初始连接完成,然后才开始播放视频......
如何在加载主视图之前强制播放视频?或者我可以延迟加载主XIB?
Dar*_*ust 13
你无法摆脱静态的飞溅图像.虽然它显示,操作系统正在加载应用程序并实例化东西,直到它准备好调用你的UIApplicationDelegate.因此,您所能做的就是使用无闪光(黑屏几秒钟)或使您的电影完全与显示的闪屏一起开始,因此看起来静态图像会突然变形.
要在电影加载时摆脱黑屏,您可以尝试使播放器透明,并在显示启动图像的播放器后面放置一个UIImageView.行为将是这样的:
至少在理论上,这应该导致静态图像突然开始动画的效果.
但是如果你根本不使用闪屏(很多游戏都是这样),那么电影播放器一开始就显示黑屏并不重要,你不会注意到.
关于在UIImageView中显示启动画面:遗憾的是,您必须测试界面旋转并手动加载图像,无法查询显示的启动画面.如果你只支持一个界面方向(同样,许多游戏都这样做)你当然没有这个问题.
小智 10
假设您正在使用UIViewControllers,现在有一个更好的解决方案.
而不是使用MPMoviePlayerController,使用MPMoviePlayerViewController.以下是一些示例代码,改编自以下问题:
- (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];
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
13116 次 |
| 最近记录: |