OK I have a strange one
I have some audio files in my main bundle
audio1.caf
audio2.caf
etc.
I put them into an NSDictionary with objects and keys so that when a certain button is tapped a detailView is loaded and then in that view I have some buttons and AVAudioPlayers which when tapped are to play the audio they are related to.
My problem is that when the first button is tapped the correct audio plays but on other buttons the same audio plays.
I removed the audio1.caf from my main bundle, and from the apps folder on the computer, I disconnected the button from the action in the IB, I commented out the AVAudioPlayer associated with the button and I commented out the path to the file and I deleted the app from my phone and even did a hard restart to reset it.
After all that I loaded the app onto my phone pressed the 2nd button linked to another audio file that does exist in the main bundle and guess what?
The deleted audio played, HOW?
Could someone explain this to me and help me make this work right.
Here is my dictionary in the mainViewController
And this is the code in the FinalDetailViewController
so I have the audio in the main bundle which is the object for the key in myDictionary.
I start the audio session and set up the path to the audio files and have a separate AVAudioPlayer alloc and init the file and I have separate buttons and IBActions to play the separate files.
Why is the same audio being played on all even when it doesn't exist?
I'm wondering if when I alloc the first player and file it stays in memory and so just keeps playing over and over. But there is no way now to release the player. Do I need separate audio sessions?
HELP
I have some audio files in my main bundle
audio1.caf
audio2.caf
etc.
I put them into an NSDictionary with objects and keys so that when a certain button is tapped a detailView is loaded and then in that view I have some buttons and AVAudioPlayers which when tapped are to play the audio they are related to.
My problem is that when the first button is tapped the correct audio plays but on other buttons the same audio plays.
I removed the audio1.caf from my main bundle, and from the apps folder on the computer, I disconnected the button from the action in the IB, I commented out the AVAudioPlayer associated with the button and I commented out the path to the file and I deleted the app from my phone and even did a hard restart to reset it.
After all that I loaded the app onto my phone pressed the 2nd button linked to another audio file that does exist in the main bundle and guess what?
The deleted audio played, HOW?
Could someone explain this to me and help me make this work right.
Here is my dictionary in the mainViewController
Code:
if ([vc isKindOfClass:[FinalDetailViewController class]])
{
FinalDetailViewController*lcVC =(FinalDetailViewController*)vc;
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"audio1.caf",@"firstAudioKey",
@"audio2.caf",@"secondAudioKey",nil];
lcVC.myDictionary =myDictionary;
}
[self.navigationController pushViewController:vc animated:YES];
}
And this is the code in the FinalDetailViewController
Code:
- (void)viewDidLoad
{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:self.firstAudioKey ofType:@"caf"]];
theAudio2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
theAudio2.delegate =self;
theAudio2.volume = 10.0;
theAudio2.numberOfLoops = 0;
NSURL *url2 = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:self.secondAudioKey ofType:@"caf"]];
theAudio3 = [[AVAudioPlayer alloc] initWithContentsOfURL:url2 error:nil];
theAudio3.delegate =self;
theAudio3.volume = 10.0;
theAudio3.numberOfLoops = 0;
}
-(IBAction)buttonPressed:(id)sender {if ([theAudio2 isPlaying]){[theAudio2 pause]; }else{[theAudio2 play];}}
-(IBAction)buttonPressed2:(id)sender {if ([theAudio3 isPlaying]){[theAudio3 pause]; }else{[theAudio3 play];}}
so I have the audio in the main bundle which is the object for the key in myDictionary.
I start the audio session and set up the path to the audio files and have a separate AVAudioPlayer alloc and init the file and I have separate buttons and IBActions to play the separate files.
Why is the same audio being played on all even when it doesn't exist?
I'm wondering if when I alloc the first player and file it stays in memory and so just keeps playing over and over. But there is no way now to release the player. Do I need separate audio sessions?
HELP