【问题标题】:Why won't my MPMoviePlayerController play?为什么我的 MPMoviePlayerController 不能播放?
【发布时间】:2013-02-24 23:50:59
【问题描述】:

我正在尝试使用下面的代码播放基本的 .mov 视频文件,但是当按下我分配了动作的按钮时,唯一显示的是黑框,但没有播放视频.任何帮助表示赞赏。谢谢。

@implementation SRViewController

-(IBAction)playMovie{
    NSString *url = [[NSBundle mainBundle]
                     pathForResource:@"OntheTitle" ofType:@"mov"];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
                                       initWithContentURL: [NSURL fileURLWithPath:url]];

    // Play Partial Screen
    player.view.frame = CGRectMake(10, 10, 720, 480);
    [self.view addSubview:player.view];

    // Play Movie
    [player play];
}

@end

【问题讨论】:

  • 是否显示黑屏?

标签: ios mpmovieplayercontroller


【解决方案1】:

假设的前提条件:您的项目正在使用 ARC

您的 MPMoviePlayerController 实例仅是本地实例,ARC 无法告诉您需要保留该实例。由于控制器没有被其视图保留,结果是您的MPMoviePlayerController 实例将在您的playMovie 方法执行后直接释放。

要解决该问题,只需将播放器实例的属性添加到您的 SRViewController 类并将实例分配给该属性即可。

标题:

@instance SRViewController

   [...]

   @property (nonatomic,strong) MPMoviePlayerController *player;

   [...]

@end

实施:

@implementation SRViewController

   [...]

    -(IBAction)playMovie
    {
        NSString *url = [[NSBundle mainBundle]
                         pathForResource:@"OntheTitle" ofType:@"mov"];
        self.player = [[MPMoviePlayerController alloc]
                                           initWithContentURL: [NSURL fileURLWithPath:url]];

        // Play Partial Screen
        self.player.view.frame = CGRectMake(10, 10, 720, 480);
        [self.view addSubview:self.player.view];

        // Play Movie
        [self.player play];
    }

    [...]

@end

【讨论】:

  • 很好的答案!谢谢!我现在可以加载视频,但是当它播放时,它只播放音频。我不确定问题是什么,所以任何帮助将不胜感激。谢谢!
  • OK...我解决了问题...视频的编解码器错误。
  • 我讨厌当一个问题得到回答但创作者只是离开而不给分或任何东西
猜你喜欢
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 2013-10-10
相关资源
最近更新 更多