我是 ios 开发新手。我在 AudioToolBox 框架的帮助下使用音频队列服务从https://github.com/vecter/Audio-Queue-Services-Example下载了示例录音机项目。在该示例项目中录制了音频格式是.aif。同时运行下载的示例项目工作正常。在示例示例项目中使用如何录制音频,如 .mp3 格式。我该怎么做?
只是我已将kAudioFileAIFFType更改为kAudioFileMP3Type我从 nslog 收到消息
//---------nslog message--------------
Not recording, returning
Writing buffer 0
//------------------
- (void)startRecording
{
[self setupAudioFormat:&recordState.dataFormat];
recordState.currentPacket = 0;
OSStatus status;
status = AudioQueueNewInput(&recordState.dataFormat,
AudioInputCallback,
&recordState,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
&recordState.queue);
if (status == 0)
{
// Prime recording buffers with empty data
for (int i = 0; i < NUM_BUFFERS; i++)
{
AudioQueueAllocateBuffer(recordState.queue, 16000, &recordState.buffers[i]);
AudioQueueEnqueueBuffer (recordState.queue, recordState.buffers[i], 0, NULL);
}
status = AudioFileCreateWithURL(fileURL,
kAudioFileMP3Type,
&recordState.dataFormat,
kAudioFileFlags_EraseFile,
&recordState.audioFile);
if (status == 0)
{
recordState.recording = true;
status = AudioQueueStart(recordState.queue, NULL);
if (status == 0)
{
labelStatus.text = @"Recording";
}
}
}
if (status != 0)
{
[self stopRecording];
labelStatus.text = @"Record Failed";
}
}
//------------------------------------------------ --------------------------
- (void)startPlayback
{
playState.currentPacket = 0;
[self setupAudioFormat:&playState.dataFormat];
OSStatus status;
status = AudioFileOpenURL(fileURL, kAudioFileReadPermission, kAudioFileMP3Type, &playState.audioFile);
if (status == 0)
{
status = AudioQueueNewOutput(&playState.dataFormat,
AudioOutputCallback,
&playState,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
&playState.queue);
if (status == 0)
{
// Allocate and prime playback buffers
playState.playing = true;
for (int i = 0; i < NUM_BUFFERS && playState.playing; i++)
{
AudioQueueAllocateBuffer(playState.queue, 16000, &playState.buffers[i]);
AudioOutputCallback(&playState, playState.queue, playState.buffers[i]);
}
status = AudioQueueStart(playState.queue, NULL);
if (status == 0)
{
labelStatus.text = @"Playing";
}
}
}
if (status != 0)
{
[self stopPlayback];
labelStatus.text = @"Play failed";
}
}