在 iPad 上播放介绍影片
我正在尝试播放介绍电影(如启动画面)。它曾经在 sdk 3.0 上运行良好,但现在我在 iPad 上运行。它没有运行电影,而是在视图出现之前显示黑屏。 这是我的代码
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"m4v" inDirectory:nil];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.fullscreen=YES;
moviePlayer.view.frame = CGRectMake(0, 0,1024,768);
[moviePlayer setShouldAutoplay:YES];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setRepeatMode:MPMovieRepeatModeNone];
[moviePlayer prepareToPlay];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
return YES;
}
,这是我的 moviePlaybackDidFinish
- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
theMovie.initialPlaybackTime = -1;
[theMovie pause];
[theMovie stop];
[theMovie release];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
我不知道我在这里缺少什么?
感谢您的帮助....
更新我刚刚发现它播放声音但没有视频......这很明显吗?请帮忙
i am trying to play an intro movie (like a splash screen). it used to work fine for sdk 3.0 but now i am doing it for iPad. and its not running movie instead it just show black screen before view appears.
here is my code
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"m4v" inDirectory:nil];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.fullscreen=YES;
moviePlayer.view.frame = CGRectMake(0, 0,1024,768);
[moviePlayer setShouldAutoplay:YES];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setRepeatMode:MPMovieRepeatModeNone];
[moviePlayer prepareToPlay];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
return YES;
}
and here is my moviePlaybackDidFinish
- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
theMovie.initialPlaybackTime = -1;
[theMovie pause];
[theMovie stop];
[theMovie release];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
i dont know what i am missing here?
thanks for any help....
UPDATE i just found out that it plays sound but no video....is this obvious?pls help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在
MPMoviePlayerViewController
上使用MPMoviePlayerController
时,我认为您需要在调用 play 之前将播放器的视图添加到视图层次结构中,根据文档:这可能解释了为什么您听到音频但看不到任何东西,很确定您也需要先设置应用程序窗口(
[window makeKeyAndVisible];
等)As you're using
MPMoviePlayerController
overMPMoviePlayerViewController
I think you need to be adding the player's view to your view hierarchy before calling play, as per the docs:this might explain why you're hearing audio but not seeing anything, pretty sure you need to setup the app window first too (
[window makeKeyAndVisible];
etc)