我是ios开发的新手。我在AudioToolBox框架的帮助下使用Audio Queue Service从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";
}
}
答案 0 :(得分:0)
不,你不能录制到MP3。核心音频文档(核心音频pdf第51页)清楚地解释了这背后的原因。
用他们自己的话说 - &gt;
iOS包含表2-5中列出的录制编解码器。如您所见,MP3和AAC录音都不可用。 这是由于这些格式的高CPU开销和随之而来的电池消耗。
iOS:录制音频格式