gpt4 book ai didi

ios - MPMoviePlayerController 仅显示黑屏

转载 作者:行者123 更新时间:2023-11-29 03:36:17 24 4
gpt4 key购买 nike

我试图在启动屏幕显示后直接播放视频,但我所看到的只是黑屏,状态栏显示在顶部。目前,这就是应用程序执行的所有操作,因此据我所知,没有其他任何事情会停止视频播放。

视频在 iPad 上播放没有任何问题,格式似乎正确等等。我的目标是 iOS 7,我尝试使用不同的视频,也尝试使用 MPMoviePlayerViewController。所有最终都会得到相同的结果。

这是我正在使用的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:@"IntroMovie" withExtension:@"mov"];

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

[moviePlayer prepareToPlay];

[self.window addSubview:moviePlayer.view];

[moviePlayer play];

return YES;
}

最佳答案

您需要创建 MPMoviePlayerViewController 对象而不是前一个。应在 makeKeyAndVisible 之后调用 playMovie 方法。如果仍然不起作用,请尝试添加断点并检查给定视频的 URL 是否正确以及是否已更改添加到复制捆绑资源。希望这有帮助

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self playMovie];
return YES;
}


-(void)playMovie
{
NSURL *movieURL;
NSBundle *bundle = [NSBundle mainBundle];
if(bundle != nil)
{
NSString *moviePath = [bundle pathForResource:@"intro" ofType:@"m4v"];
if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];

}
}


moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.moviePlayer.scalingMode = MPMovieScalingModeFill;
[self.viewController presentViewController:moviePlayer animated:NO completion:^{

}];
[moviePlayer.moviePlayer play];




}

关于ios - MPMoviePlayerController 仅显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19138607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com