在 iPad 上播放介绍影片

发布于 2024-09-28 12:55:49 字数 1741 浏览 0 评论 0原文

我正在尝试播放介绍电影(如启动画面)。它曾经在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-10-05 12:55:49

当您在 MPMoviePlayerViewController 上使用 MPMoviePlayerController 时,我认为您需要在调用 play 之前将播放器的视图添加到视图层次结构中,根据文档:

[player.view setFrame: myView.bounds];  // player's frame must match parent's
[myView addSubview: player.view]; //add the player' view

这可能解释了为什么您听到音频但看不到任何东西,很确定您也需要先设置应用程序窗口([window makeKeyAndVisible]; 等)

As you're using MPMoviePlayerController over MPMoviePlayerViewController I think you need to be adding the player's view to your view hierarchy before calling play, as per the docs:

[player.view setFrame: myView.bounds];  // player's frame must match parent's
[myView addSubview: player.view]; //add the player' view

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文