Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCODE AVAudioPlayer error regarding AudioQueue: request to trim 0 + 1676 = 1676 frames from buffer containing 1152 frames

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.

like image 796
user1771823 Avatar asked May 27 '26 08:05

user1771823


1 Answers

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.

like image 137
Benny Avatar answered May 30 '26 07:05

Benny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!