That was so easy. There is one more thing. When you use e.g NSTimer
you must ivalidate
it in some place. When you use AVAudioPlayer
you have to stop
it in some place.
[player stop];
Domanda
i'm working on little game, and i've got problem with background music. I use AVAudioPlayer
to play loop music. It's look like below:
NSString *path = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"ogg"];
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:&error];
NSLog(@"%@", [error description]);
[player setNumberOfLoops:-1];
player.delegate = self;
[player play];
I've got in Supproting Files
file background.ogg
, background.mp3
, background.wav
and no one plays. What is wrong with it?
And when i use NSLog
to print description error i've got:
Error Domain=NSOSStatusErrorDomain Code=1954115647 "The operation couldn’t be completed. (OSStatus error 1954115647.)"
Please help.
Soluzione 2
That was so easy. There is one more thing. When you use e.g NSTimer
you must ivalidate
it in some place. When you use AVAudioPlayer
you have to stop
it in some place.
[player stop];
Altri suggerimenti
Some times,just because your audio file's quality is not match what it need,such as sampling rate.Please check up whether your audio sampling rate is lower than 24kHz. I have tested some audio,And I found that when the audio sampling rate is higher than 44kHz,it work great, but if it is lower than 44kHz & higher than 22kHz, the AudioToolbox can't play the sounds first while AVAudioPlayer can work some times. And if it is lower than 22kHz both them will can't play these audio files.(these audio's file format which I tested just "m4a","mp3","wav")
By the way,If you want to convert the low sampling rate audio to 44kHz "m4a" file use itunes,it also can't work.Don't waste your time on this.