Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios avaudio的播放速度非常低_Ios_Xcode_Avaudioplayer - Fatal编程技术网

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];

将其发送到扬声器工作。第二个“环境”不起作用。谢谢你的帮助。