Vote count:
0
This method is correctly connected to a NSButton, the *url object is correctly initialized with a real resource on the filesystem, the mp3file file is added to the application bundle, when i click the button, i can see the "NSLog(@"playSound: path %@", url);" to log correctly, the url refers to a real file on the disk. I can see from the debugger that the *error object is nil while the *audioPlayer object is correctly initialized. The volume of my mac is turned on :) but no sound is coming out of the speaker when i click the button.
I don't see any reason why this code should not work.
Please help!
- (IBAction)playSound:(id)sender {
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSURL *url = [[NSBundle mainBundle] URLForResource:[standardDefaults stringForKey:@"SoundKey"] withExtension:@"mp3"];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[audioPlayer prepareToPlay];
if ([audioPlayer isPlaying]) {
[audioPlayer pause];
} else {
[audioPlayer play];
}
#if DEBUG
if (error) {
NSLog(@"playSound: error: %@", error);
}
NSLog(@"playSound: path %@", url);
#endif
}
asked 22 secs ago
Aucun commentaire:
Enregistrer un commentaire