当使用AudioQueue播放PCM数据时,我遇到了问题。当使用iPhone的扬声器时,音量很低;我甚至把系统音量提高到了最大值。但是,当我使用耳机的时候,音量是可以的。
我将数据插入队列中,如下所示:
memcpy(mBuffers[mIndex]->mAudioData, pcmData, mBufferByteSize);
mBuffers[mIndex]->mAudioDataByteSize = mBufferByteSize;
mBuffers[mIndex]->mPacketDescriptionCount = mBufferByteSize/2;
OSStatus status = AudioQueueEnqueueBuffer(mQueue, mBuffers[mIndex], 0, NULL);
NSLog(@"fill audio queue buffer[%d]",mIndex);
if(mIndex == kNumberBuffers - 1) {
isStartPlay = YES;
mIndex = 0;
AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0);
status = AudioQueueStart(mQueue, NULL);
}else {
mIndex++;
}我把音量设成这样:
AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0);发布于 2017-06-28 14:31:50
对于那些仍然存在此问题的人,甚至在SpeakHere示例代码上也是如此。在所有其他解决方案中,这个解决方案对我来说效果很好:
//ViewController.m
#import "ViewController.h"
@interface ViewController ()
{ AVAudioSession *session; }
- (void)viewDidLoad {
[super viewDidLoad];
//This ensures it plays properly on speaker output
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
error:nil];
}https://stackoverflow.com/questions/32599351
复制相似问题