【问题标题】:Init and playing MPMoviePlayerController returns black screen初始化并播放 MPMoviePlayerController 返回黑屏
【发布时间】:2012-04-26 03:51:08
【问题描述】:

我正在尝试使用 Xcode 中的一些示例代码在 iPhone Simulator 5.1 下播放 mp4 视频。我创建了 MPMovieViewController 和 MPMovieController,提供了一个包含 mp4 的本地路径并将其作为子视图添加到我的根控制器。

当我在 iPhone 模拟器下运行它时,只显示后屏。我已经尝试了一些关于 SO 中相同问题的建议,但仍然不起作用。

代码如下:

    NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];

    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];        
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];

    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

    [player.view setFrame: self.view.bounds];  // player's frame must match parent's
    [self.view addSubview: player.view];
    player.view.frame = self.view.frame;

    player.initialPlaybackTime = -1.0;
    [player prepareToPlay];
    [player play];

我哪里做错了?

PS:我在 Xcode 4.3.2 上

【问题讨论】:

    标签: ios5 mpmovieplayercontroller xcode4.3


    【解决方案1】:

    我也遇到了同样的问题,我所做的就是让 player 成为一个强属性并合成它。有效。

    应该也适用于您的情况。!

    【讨论】:

    • 谢谢!瞬间,我不会猜到的。 (只要将视图添加到另一个屏幕视图,其他视图及其视图控制器似乎就会保留,但显然这个不是。或者我还没有在屏幕上显示父视图。不确定。)
    • 天啊!非常感谢。我被困了4天。非常感谢。
    【解决方案2】:

    决定并使用MPMoviePlayerViewController 或 MPMoviePlayerController,但不能同时使用。

    NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];
    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];        
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
    

    或

    NSURL *myURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VIDEO_CX75_01" ofType:@"mp4"]];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
    player.view.frame = self.view.bounds;
    [self.view addSubview:player.view];
    player.initialPlaybackTime = -1.0;
    [player prepareToPlay];
    [player play];
    

    【讨论】:

    • 两者都试过了,但似乎都不起作用,仍然显示黑屏而不是电影帧。 PS:我已经添加了MediaPlayer.framework,可以通过QuickTime确认mp4电影正在播放。
    猜你喜欢
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多