ios - 不显示电影,出现黑屏

标签 ios objective-c mpmovieplayercontroller mpmovieplayer

我的电影播放器​​正在播放但没有播放任何视频。它只播放声音。

我的代码如下:

    self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:nil];

    self.moviePlayer.view.frame=CGRectMake(10, (self.view.frame.size.height-200-64)/2, 300, 200);

    [self.moviePlayer setControlStyle:MPMovieControlStyleDefault];

    [self.moviePlayer setShouldAutoplay:YES];
    self.moviePlayer.allowsAirPlay = YES;
    self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

    self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
     [self.moviePlayer setContentURL:[NSURL URLWithString:AttachmentUrl]];
    [self.view addSubview:self.moviePlayer.view];

    self.moviePlayer.fullscreen=YES;
    [self.moviePlayer prepareToPlay];

    [self.moviePlayer play];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieloadStateHandler:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:nil];

请建议我需要做什么。

最佳答案

我的经验是最好使用:MPMoviePlayerViewController

例如:

MPMoviePlayerViewController *mvPlayerController = [[MPMoviePlayerViewController alloc]
                               initWithContentURL:[NSURL URLWithString:AttachmentUrl]];

关于ios - 不显示电影,出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22509816/

相关文章:

iphone - MPMoviePlayerController 在纵向项目中以横向模式全屏显示

ios - 在基于 Cordova 的 Xcode 项目中自动添加构建阶段

ios - 使用自动调整大小时,UIView 不会在旋转时调整大小

iphone - 在 MPMoviePlayerController 上调用播放后,电影播放有一些延迟

ios - 无法使用 NSUserDefaults 保存整数

objective-c - 将文件类型/扩展名关联到基于非文档的 Cocoa 应用程序

ios - 无法从 mainBundle 播放 MP4 视频文件

iphone - writeToFile 失败 - 如何调试它失败的原因(什么工具)?

iphone - 如何使用金额对包含对象作为数据的NSMutableArray进行排序

iphone - 将字符串 MM/DD/YYYY 转换为 NSDate