2013-03-14 207 views
0

我有一个电影,加载正常,播放良好,但它会播放页面加载。我希望它加载一个暂停的状态,要求用户按下播放来观看。ipad电影暂停,而不是播放时,页面加载

- (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]; 
} 

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

回答

1

把你的代码blurb你已经写在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中

+0

太棒了 - 非常感谢。只是出于兴趣,开始时会有一些微小的变动,然后停下来。任何想法,为什么这可能是?非常小的一点,但只是感兴趣。再次感谢。 – RGriffiths 2013-03-14 20:08:09

1

删除代码,您可能想尝试shouldAutoplay设置MPMoviePlayerController属性NO

在呼叫前添加以下行;

moviewPlayerController.shouldAutoplay = NO; 

从参考:

shouldAutoplay 

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

@property (nonatomic) BOOL shouldAutoplay 

讨论

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

可用性 适用于iOS 3.2或更高版本。 已申报

+0

这也很棒 - 它阻止了最初的移动。感谢你们两位。 – RGriffiths 2013-03-14 20:09:50