Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy will this sound loop not stop?
    primarykey
    data
    text
    <p>I made a sound loop in my app that I want to stop when the user presses the 'ok' button on a <code>UIAlertView</code> that comes up. </p> <p>I have 2 problems though:</p> <hr> <h2>First</h2> <p>When I have breakpoints on and I set a breakpoint for all exceptions, an exception appears on <code>[audioPlayer play]</code> but no error is shown on the log and the app does not crash after 'F8-ing' through the exception except there is no sound. </p> <hr> <h2>Second</h2> <p>The other problem I'm having is that the audio file wont stop after the user taps the 'ok' button, and breakpointing through shows that it does read the <code>[audioPlayer stop]</code> call. I have no idea what is causing these errors and nothing I do seems to help.</p> <hr> <h2>Code</h2> <pre><code>AVAudioPlayer *audioPlayer; -(void)done { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Timer Done" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil]; [alert show]; [self playAlert]; } -(void)playAlert { NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Alarm" ofType:@"caf"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil]; audioPlayer.numberOfLoops = -1; //infinite [audioPlayer play]; } - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { if ([audioPlayer isPlaying]) { [audioPlayer stop]; } } } </code></pre> <p>Please let me know what I can do to fix this.</p>
    singulars
    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.
    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