How to play sound automatically when scrolling to the next page?

Posted by viper15 on Stack Overflow See other posts from Stack Overflow or by viper15
Published on 2009-08-20T17:15:16Z Indexed on 2010/05/14 19:04 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

I'm using Page Control example from Apple. I want to be able to scroll horizontally to certain page and get the sound automatically play when viewing that page? And then sound stop when viewing the other page?

So, for example. On page 1, i have some texts. When i go to the next page which is on page 2, i want sound to be automatically play and stop when i go to page 3.

I'm planning to use If statements (since it's not that many pages) to determine which page will get the sound.

My question is simple. How do you get the sound play automatically when viewing certain page? By the way, I'm planning to use System Sound.

I know how to play the sound using button. But how do you get it automatically - start when certain page appear and stop when moving to the next page.

Thank you in advance!

Edited:

I put in this code in ViewDidLoad but the sound played on sooner before it reach the page intended:

// Set the label and background color when the view has finished loading.
- (void)viewDidLoad {
    pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1];
    self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
    if (pageNumber == 3) {
    	NSString *path = [[NSBundle mainBundle] pathForResource:@"crunch" ofType:@"wav"];
    	SystemSoundID soundID;
    	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    	AudioServicesPlaySystemSound(soundID);
}
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk