MPMoviePlayerController仅显示黑屏

时间:2013-10-02 13:53:59

标签: ios objective-c mpmovieplayercontroller

我试图在启动屏幕显示后直接进行视频播放但是我看到的是一个状态栏显示在顶部的黑屏。目前这是所有应用程序都这样做的,据我所知,没有其他任何事情可以阻止视频播放。

视频在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;
}

2 个答案:

答案 0 :(得分:1)

你需要创建MPMoviePlayerViewController对象而不是前者。应该在makeKeyAndVisible之后调用playMovie方法。如果它仍然无法工作尝试添加断点并检查给定视频的URL是否正确以及是否已经添加到Copy Bundle资源。希望这有帮助

 - (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];




}

答案 1 :(得分:0)

假设您没有拼写错误和正确的项目设置,您可能遇到的唯一问题是在用于创建“mov”文件的编解码器中。尝试使用其他一些mov文件或尝试将你的mov文件放入手机库并尝试从那里播放