iOS:MPMoviePlayer无法播放

时间:2012-11-06 12:59:31

标签: ios mpmovieplayercontroller

使用本文底部的代码,我可以成功地显示电影。但是我现在需要使用moviePlayer作为属性而不是局部变量。因此,在头文件中添加以下内容:

  @property (retain, nonatomic) MPMoviePlayerController *mPlayer;

......并将其合成为:

   @synthesize mPlayer = _mPlayer

这是原始代码。这很好用。我改变的只是初始化行,而不是使用局部变量我使用属性。甲

  MPMoviePlayerController * mPlayer = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL] autorelease];
    mPlayer.shouldAutoplay=YES;

    [self.welcomeImage setUserInteractionEnabled:YES];

    [mPlayer.view setFrame: self.welcomeImage.bounds];  // player's frame must match parent's
    [self.welcomeImage addSubview:mPlayer.view];
    mPlayer.scalingMode = MPMovieScalingModeAspectFit;
    mPlayer.controlStyle = MPMovieControlStyleEmbedded;
    [mPlayer prepareToPlay];
    [mPlayer play];

我只是得到一个黑盒子,没有控件或视频。我做错了什么?

1 个答案:

答案 0 :(得分:0)

您没有使用合成财产。将mPlayer更改为_mPlayer。

_mPlayer = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL] autorelease];
_mPlayer.shouldAutoplay=YES;

[self.welcomeImage setUserInteractionEnabled:YES];

[_mPlayer.view setFrame: self.welcomeImage.bounds];  // player's frame must match parent's
[self.welcomeImage addSubview:_mPlayer.view];
_mPlayer.scalingMode = MPMovieScalingModeAspectFit;
_mPlayer.controlStyle = MPMovieControlStyleEmbedded;
[_mPlayer prepareToPlay];
[mPlayer play];

只要您的videoURL有效,这应该有效。