I am playing audio from playlist in my app. I am using following code in viewDidLoad function:-
NSURL *url = [NSURL URLWithString:FeedLink];
NSData *_objectData = [NSData dataWithContentsOfURL:url];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.delegate = self;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
audioPlayer.numberOfLoops = 0;
On Play button it play the audio and it also playing fine in background or when i go to another class.
The problem is when i came back to this view controller and select another audio then the previous Playing audio is not stopped. and both are Playing simultaneously.
Can any one help me in this that when i came back to viewDidLoad from anther view controller it stop the playing audio and only play one at a time. Thanks in advance