tags:

views:

189

answers:

2

I'm using AVAudioPlayer to play sound effects in an iPhone game. This is part of my code:

AVAudioPlayer *player = [dict objectForKey:@"Player"];
if (player.playing) {
    player.currentTime = 0;
} else {
    [player play];
}

One sound that can be played repeatedly and very often, since it plays based on user interaction. As the user moves his finger, I call this piece of code repeatedly.

If you do so, the application hangs and this is the error I get on the crash log:

0   libSystem.B.dylib               0x3146bb18 semaphore_timedwait_signal_trap + 8
1   libSystem.B.dylib               0x3146297c semaphore_timedwait_signal + 8
2   libSystem.B.dylib               0x3145f0fe _pthread_cond_wait + 898
3   libSystem.B.dylib               0x3145f25a pthread_cond_timedwait_relative_np + 10
4   AudioToolbox                    0x348ddd50 CAGuard::WaitFor(unsigned long long) + 116
5   AudioToolbox                    0x3491b94c ClientAudioQueue::ServicePendingCallbacks() + 232
6   AudioToolbox                    0x3491ba60 AudioQueueReset + 44
7   AVFoundation                    0x34d16668 -[AVAudioPlayer setCurrentTime:] + 444

This looks to me like a locking issue inside AVAudioPlayer, and I haven't been able to solve it. I tried with different sound formats (CAFF and IMA4) and both fail in the same way.

Any pointer? I'd really like to stick to AVAudioPlayer since its much simpler to use than Audio Queues, but I need the sounds to play and not crash my application.

A: 

I could not find a way to solve this issue. I worked around it by using OpenAL for my sound needs instead.

pgb
A: 

Have you tried calling stop before reseting the currentTime, and then calling play? Editing your example:

if (player.playing) {
    [player stop];
    player.currentTime = 0;
    [player play];
} else {
    [player play];
}

I have no idea if this is the case, but perhaps resetting the currentTime while the sound is playing might be causing the locking problems. The docs certainly don't warn against this or anything.

Bdebeez