Note that there are some explanatory texts on larger screens.

plurals
  1. POAVAudioPlayer pausing issue
    text
    copied!<p>In my project, I have an AVAudioPlayer which plays a song. After I pause it, and hit play again, it starts over instead of playing where I paused. Why is that happening? Also, when I press play for the first time, it loads the song about 3-4 seconds. I thought I solved it by loading it on the other thread, but it still loads too slow (at least the view doesn't freeze anymore). How can I fix that? Here's the code:</p> <pre><code>- (IBAction)play:(id)sender { songIsCurrentlyPaused = NO; if(songIsCurrentlyPaused==YES){     [self.background play]; } else { playQueue = dispatch_queue_create("volume_change", NULL); dispatch_async(playQueue, ^{ NSString *filePath = [[NSBundle mainBundle]pathForResource:@"some_song" ofType:@"mp3"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; self.background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; self.background.delegate = self; [self.background setNumberOfLoops:1]; [self.background setVolume:0.5]; [self.background play]; }); [trackNameLabel setText:@"Currently playing :\n some_song"]; self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(updateProgressBar) userInfo:nil repeats:YES];     } } - (IBAction)pause:(id)sender { songIsCurrentlyPaused = YES; [self.background pause]; [trackNameLabel setText:@"Currently playing : some_song (paused)"]; [self.progressBar setProgress:self.background.currentTime/self.background.duration animated:YES]; } </code></pre> <p>Thanks!</p>
 

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