Ios avaudio的播放速度非常低
我有录音和回放程序。请参阅下面的代码。唯一的问题是,我的设备上的播放速度非常低。模拟器上的音量正常,我的设备音量一直在上升。还有什么我需要安排的吗。 以下是记录代码:Ios avaudio的播放速度非常低,ios,xcode,avaudioplayer,Ios,Xcode,Avaudioplayer,我有录音和回放程序。请参阅下面的代码。唯一的问题是,我的设备上的播放速度非常低。模拟器上的音量正常,我的设备音量一直在上升。还有什么我需要安排的吗。 以下是记录代码: NSArray *pathComponents = [NSArray arrayWithObjects: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) la
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
[recorder record];
播放:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:nil];
[player setDelegate:self];
player.meteringEnabled = YES;
player.volume = 1.0;
[player play];
将您的扬声器设为默认值,因为音频通过其他路径时会出现一些时间问题
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&sessionError];
尝试AVAudioSessionCategoryAmbient
模式播放声音时音量很大
[session setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
将其发送到扬声器工作。第二个“环境”不起作用。谢谢你的帮助。