RGriffiths
RGriffiths

Reputation: 5970

ipad movie paused rather play when page is loaded

I have a movie that loads fine and plays fine but it plays as soon as the page loads. I would like it to load in a paused state requiring the user to hen press play to watch.

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

The pause on the last line does not seem to do anything. Any help? Thanks

Upvotes: 0

Views: 151

Answers (2)

Till
Till

Reputation: 27597

You might want to try setting the MPMoviePlayerController property shouldAutoplay to NO.

Add the following line before your prepareToPlay call;

moviewPlayerController.shouldAutoplay = NO;

From the reference:

shouldAutoplay

A Boolean that indicates whether a movie should begin playback automatically.

@property (nonatomic) BOOL shouldAutoplay

Discussion

The default value of this property is YES. This property determines whether the playback of network-based content begins automatically when there is enough buffered data to ensure uninterrupted playback.

Availability Available in iOS 3.2 and later. Declared In

Upvotes: 1

C0L.PAN1C
C0L.PAN1C

Reputation: 12243

Put your code blurb you've written above in viewwillappear. Then add play at the end like so:

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

at the end of it.

In a viewdidappear do a

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

Remember to remove code from viewDidLoad

Upvotes: 1

Related Questions