I’ve got an application with a navigation tree. Somewhere there is an audio player with an mp3.
UITabViewController // controlled by AppDelegate.m
-> UINavigationController
-> UITableViewController // controlled by TableViewController.m
-> UIViewController // with my AVAudioPlayer controlled by AudioViewController.m
In AudioViewController.m I have all my audio engine so i play/pause/stop it, and even kill it when pressing back button (using viewWillDisappear etc) – it plays only in this one view, not another, and it’s good.
However there is an issue when i press home button while playback is on. It stops, but after going back to my app, it plays again from remembered time stamp.
I tried all this:
- (void)viewDidUnload
{
[super viewDidUnload];
[self audioStop:self];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self audioStop:self];
[super viewWillDisappear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self audioStop:self];
}
- (void)viewWillUnload
{
[self audioStop:self];
[super viewWillUnload];
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self audioStop:self];
}
But nothing happens.
Now i know that to manage if home button was pressed, i need to use applicationWillResignActive method from AppDelegate, but i have totally no idea how do i stop my audioplayer from here. I’m quite new to iOS and i’m not familiar with how delegates work, so please help me work this out.
Let you AppDelegate hold a reference for you UIViewcontroller some how and call it. Make sense?
Edit:
This way you can access the audio player from TableViewController object. If you hold TableViewController object this way it should be easy for you.
something like that ..