不显示电影,黑屏出现

时间:2014-03-19 14:58:10

标签: 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];

请建议我需要做什么。

1 个答案:

答案 0 :(得分:1)

我的经验是,最好使用:MPMoviePlayerViewController

例如:

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