Note that there are some explanatory texts on larger screens.

plurals
  1. PODifficulty playing Audio file
    primarykey
    data
    text
    <p>Hi there I'm trying to play a page turn sound when I click on the "next" button to take me to the next page, but the sound does not come, while when I press the "play" button for the music, it plays the music, can anyone help here please. Here is the code:</p> <pre><code>- (IBAction)next { // This part plays the next page turn noise NSURL *this = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/next.mp3", [[NSBundle mainBundle] resourcePath]]]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:this error:&amp;error]; [audioPlayer setDelegate:self]; audioPlayer.numberOfLoops = 0; [audioPlayer play]; // This part takes us to the next view Rabbana2 *rab = [[Rabbana2 alloc] initWithNibName:@"Rabbana2" bundle:nil]; [UIView beginAnimations:@"flipView" context:Nil]; [UIView setAnimationDuration:2]; [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [self.view addSubview:rab.view]; [UIView commitAnimations]; } // This button plays the audio - (IBAction)play { if(clicked == 0){ clicked = 1; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/rabbana1.wav", [[NSBundle mainBundle] resourcePath]]]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error]; [audioPlayer setDelegate:self]; audioPlayer.numberOfLoops = 0; [audioPlayer play]; [start setImage:[UIImage imageNamed:@"Sstop.png"] forState:UIControlStateNormal]; } else{ [audioPlayer release]; clicked = 0; [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal]; } } //If user does not do anything by the end of the sound set the button to start - (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) flag { if (flag==YES) { clicked = 0; [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload