AVAudioPlayer could not stop playing music in iOS 7.1.2

218 Views Asked by At

AVAudioPlayer starts playing music when a local notification is shown to user. After clicking the notification and app runs in foreground I could not stop the music only in iOS 7.1.2. But I can stop it in iOS 8+.
Has anyone heard any iOS 7.1.2 bug about this issue reported by Apple?

I use the same instance that I start playing the music.

// start playing the music

[self.player prepareToPlay];

// Stop playing the music

[self.player stop];
[self.player setCurrentTime:0.0f];
1

There are 1 best solutions below

2
Mihriban Minaz On

For playing use:

[self.player prepareToPlay];

For pausing/stopping use:

if (self.theAudio.playing) {
  [self.theAudio pause];
}

[self.theAudio stop];
self.theAudio.currentTime = 0;