我正在使用适用于iOS的AudioQueue按下按钮来录制用户音频数据。当用户按下按钮时,它会记录。当他释放按钮时,它会停止录制。但是,音频过早地被切断了。当用户按下停止按钮并转到收听音频时,最后一些音频丢失。我还试过用" false"来调用该功能。立即停止并听取财产回调并且没有解决它。
我如何挽救录制的最后时刻?
- (void)stopInputAudioQueue:(BOOL)immediately
{
recording = NO;
OSStatus err;
// Stop queue
err = AudioQueueStop( inputQueue, immediately ? true : false );
if( err != noErr )
MyNSLog( @"AudioQueueStop() error: %d", (int)err );
if( immediately )
{
[self disposeInputQueue];
}
}
void IsRunningProc( void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID )
{
UInt32 isRunning;
UInt32 size = sizeof( isRunning );
// We had an issue!
OSStatus result = AudioQueueGetProperty( inAQ, kAudioQueueProperty_IsRunning, &isRunning, &size );
if( result!=noErr )
{
MyNSLog( @"AudioQueueGetProperty() error: %d", result );
return;
}
AudioQueue *audioQueue = (__bridge AudioQueue *)inUserData;
if( isRunning )
{
MyNSLog( @"AudioQueue is running." );
if( [[audioQueue delegate] respondsToSelector:@selector(audioQueueStarted)] )
[[audioQueue delegate] audioQueueStarted];
}
else
{
[audioQueue disposeInputQueue];
MyNSLog( @"AudioQueue is NOT running." );
if( [[audioQueue delegate] respondsToSelector:@selector(audioQueueStopped)] )
[[audioQueue delegate] audioQueueStopped];
}
}
- (void)disposeInputQueue
{
if( inputQueue==NULL )
return;
MyNSLog( @"Calling AudioQueueRemovePropertyListener()" );
// Remove listener
AudioQueueRemovePropertyListener( inputQueue, kAudioQueueProperty_IsRunning, IsRunningProc, (__bridge void *)(self) );
MyNSLog( @"Calling AudioQueueDispose()" );
// Now get rid of the queue
AudioQueueDispose( inputQueue, true );
inputQueue = NULL;
}