Reputation: 11
Ok so the code is suppose to play the sound file when the button is first clicked and play another sound when that same button is clicked again. I put in a folder of sound files all mp3 and it only plays the file yes(I have other sounds like hi, hello, but when I put that in the pathforresouce it does't play them), and I get an nse exception error when I click the button a second time to play the second sound(went into build phases and the sound folder is there but its not playin the other audio files, only yes it plays?). So I took out the path for resource location for both files to check if my sound files are working properly and it's still playing the yes file. How is this POSSIBLE, when the yes file is only in one location in that sound folder? I even took out that sound folder from my entire project and its still playing yes with no sound file and no pathforresource ?
#import <AVFoundation/AVAudioPlayer.h>
#import "ViewController.h"
@interface ViewController ()
@end
int flag;
@implementation ViewController
AVAudioPlayer *theAudio;
- (IBAction)Yes:(id)sender {
if(flag==0){
//play file one on first button click
theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];
[theAudio play];
flag=1;
}
else if(flag==1)
{
//play file second on first button click
theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];
[theAudio play];
flag=0;
}
}
@end
Upvotes: 0
Views: 203
Reputation: 2858
The leftovers of deleted resources often remain on simulator.
Upvotes: 2