I'm using Page Control example from Apple. I've been able to play sound on the app itself using this code below but for some reasons, the sound went off early one page before it gets to the page where i set my sound to be played automatically.
- (void)viewDidLoad {
pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
if (pageNumber == 3) {
NSString *clapPath = [[NSBundle mainBundle] pathForResource:@"nearSound" ofType:@"caf"];
CFURLRef clapURL = (CFURLRef ) [NSURL fileURLWithPath:clapPath];
AudioServicesCreateSystemSoundID(clapURL, &testID);
AudioServicesPlaySystemSound(testID);
}
So, supposedly when I scroll to page 4 (pageNumber == 3), the sound will be played but it got played on page 3 (pageNumber == 2), I wonder why is that?
If it can't be solved, I'll probably have to do the workaround then, put the sound before each page that I want to insert sound.
Also, How can I play the sound again when I scroll to that same page again? It seems that the sound get triggered only once after app launched.
I would very much appreciated any of your help.