I'm using AVPlayer to stream an audio file for my project. The problem I'm facing is the audio file plays after getting pop from the AudioPlayerVC. Everything is okay when the audio plays on the AudioPlayerVC. It stops, plays and pauses too on AudioPlayerVC. But on the buffering time when I return back, it plays after some sec. I can listen to sound but cannot stop or do anything else.
- (IBAction)backAction:(id)sender {
if (_audioToPlay.playing == YES) {
[_audioToPlay stop];
} else if (_audioToPlay.playing == NO || _audioToPlay.volume == 1.0 ) {
_audioToPlay.volume = 0.0;
[_audioToPlay stop];
}
[self.navigationController popViewControllerAnimated:YES];
}
If below is not working then Refer avplayer-continues-to-play-after-viewcontroller-is-removed-from-navigationcontroller
You can do is firstly pause player
:
[yourAVPlayer pause];
Then pop
to Parent View Controller
[self.navigationController popViewControllerAnimated:YES];