录制完声音文件后,可以';我只听不到iPad的声音

录制完声音文件后,可以';我只听不到iPad的声音,ipad,ios7,avaudiorecorder,avaudiosession,Ipad,Ios7,Avaudiorecorder,Avaudiosession,我在苹果商店里有一个具有语音记录功能的应用程序。我迁移到Xcode 5.0.2和SDK 7。 除了iPadAir,iOS 6或iOS 7设备上的这一功能我没有问题。 这是我的录音程序: +(void) startRecording:(NSString *)fileName :(NSString *)fileType { NSError* theError = nil; BOOL result = YES; // Init audio with record capability AVAud

我在苹果商店里有一个具有语音记录功能的应用程序。我迁移到Xcode 5.0.2和SDK 7。 除了iPadAir,iOS 6或iOS 7设备上的这一功能我没有问题。 这是我的录音程序:

+(void) startRecording:(NSString *)fileName :(NSString *)fileType
{   NSError* theError = nil;
BOOL result = YES;

// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
result = [audioSession setCategory:AVAudioSessionCategoryRecord error:&theError];
if (!result)
{
    NSLog(@"setCategory failed %@", theError);
}
result = [audioSession setActive:YES error:nil];
if (!result)
{
    NSLog(@"setActive failed %@", theError);
}

// Verify if you have granted to use microphone. iOS 7 or later
if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
    [audioSession requestRecordPermission:^(BOOL granted) {
        if (granted) {
            // Record Sound
            [self recordNow:fileName :fileType];
        }
        else {
            // Microphone disabled code
            NSLog(@"Microphone is disabled..");

            // We're in a background thread here, so jump to main thread to do UI work.
            dispatch_async(dispatch_get_main_queue(), ^{
                [[[UIAlertView alloc] initWithTitle:@"Microphone Access Denied"
                                             message:@"This app requires access to your device's Microphone.\n\nPlease enable Microphone access for this app in Settings / Privacy / Microphone"
                                            delegate:nil
                                   cancelButtonTitle:@"Dismiss"
                                   otherButtonTitles:nil] show];
            });
        }
    }];
}
else {  // iOS 6 
    // Record sound
    [self recordNow:fileName :fileType];
}
}

// Record Sound
+(void) recordNow:(NSString *)fileName :(NSString *)fileType {
recordEncoding = ENC_AAC;

// Microphone enabled code
if (kDebugMode) {
    NSLog(@"Microphone is enabled..");
}

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
if(recordEncoding == ENC_PCM)
{
    [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
}
else
{
    NSNumber *formatObject;

    switch (recordEncoding) {
        case (ENC_AAC):
            formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC];
            break;
        case (ENC_ALAC):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless];
            break;
        case (ENC_IMA4):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
            break;
        case (ENC_ILBC):
            formatObject = [NSNumber numberWithInt: kAudioFormatiLBC];
            break;
        case (ENC_ULAW):
            formatObject = [NSNumber numberWithInt: kAudioFormatULaw];
            break;
        default:
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
    }

    [recordSettings setObject:formatObject forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];
    [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey:         AVEncoderAudioQualityKey];
}

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *recDir = [paths objectAtIndex:0];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.%@", recDir, fileName, fileType]];    
NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];

[audioRecorder recordForDuration:[[NSUserDefaults standardUserDefaults] integerForKey:kRecordForDuration]];

}

在该网站内进行了大量研究后,我发现了一条很好的评论,这让我在这里度过了美好的一天:

所以,我只是评论这一行并修复它

[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVEncoderBitRateKey];
我可以在iPad Air中再次听到唱片的声音! 为什么会这样?我还不知道,但它的作品,也许你有同样的问题,只是想留下一个关于这个案件在这个网站的日志