0

我有一部电影可以正常加载并且可以正常播放,但它会在页面加载后立即播放。我希望它以暂停状态加载,要求用户按播放观看。

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"iobserve1" ofType:@"mov"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayerController.view.frame = CGRectMake(60, 44, 900, 656);  // player's frame must match parent's
[self.movieView addSubview:moviePlayerController.view];
moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;
[moviePlayerController prepareToPlay];
[moviePlayerController pause];
}

最后一行的停顿似乎没有做任何事情。有什么帮助吗?谢谢

4

2 回答 2

1

将您在上面编写的代码简介放在 viewwillappear 中。然后像这样在最后添加播放:

-(void) viewWillAppear: (BOOL) animated {
  NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"iobserve1" ofType:@"mov"];
  NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
  moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
  moviePlayerController.view.frame = CGRectMake(60, 44, 900, 656);  // player's frame must match parent's
  [self.movieView addSubview:moviePlayerController.view];
  moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;
  [moviePlayerController prepareToPlay];
  [moviePlayerController play];
 }

最后。

在 viewdidappear 中做一个

  -(void) viewDidAppear: (BOOL) animated {
    [moviePlayerController pause];
  }

记得从 viewDidLoad 中删除代码

于 2013-03-14T19:12:59.237 回答
1

您可能想尝试将MPMoviePlayerController属性设置shouldAutoplayNO.

prepareToPlay在您的通话前添加以下行;

moviewPlayerController.shouldAutoplay = NO;

从参考:

shouldAutoplay

一个布尔值,指示电影是否应自动开始播放。

@property (nonatomic) BOOL shouldAutoplay

讨论

此属性的默认值为 YES。此属性确定当有足够的缓冲数据以确保不间断播放时,是否自动开始播放基于网络的内容。

可用性 适用于 iOS 3.2 及更高版本。宣布于

于 2013-03-14T20:05:05.513 回答