I am trying to play different sounds at different times. based on a button press or timer timeout etc. Here is the code.
To play the sound function:
-(void)myPlaySound:(NSString *)mySoundFile NumberOfLoops:(int)loopsCount ofType:(NSString *)fileType
{
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:mySoundFile
ofType:fileType]];
myAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
myAudio.volume = audioVolume;
myAudio.delegate = self;
myAudio.numberOfLoops = loopsCount;
[myAudio prepareToPlay];
[myAudio play];
}
to stop the sound:
if([myAudio isPlaying]){
[myAudio stop];
myAudio.currentTime = 0;
}
Problem: At times I get this error : AudioQueue: request to trim 0 + 1676 = 1676 frames from buffer containing 1152 frames
The error happens as soon as [myAudio play] is called.
Any help regarding this is appreciated.
I was having this problem and like Radu said, the problem that I seemed to be having was trying to play a sound while it was already playing. I don't think it's a big deal if the sound gets replaced by another sound, but be careful that you're not trying to play the same sound while it is already playing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With