Android 无法读取 iPhone 录制的音频文件

Android can't read iPhone recorded audio files

我用 iOS 应用程序录制了一些音频文件,然后通过我的网络服务器将其发送到 Android 应用程序。 Android 应用程序成功获取文件,但是当我使用 MediaPlayer class 尝试播放它时,它在第 mediaplayer.setDataSource(androidFilePath); 行报告错误 "Unable to to create media player" 顺便提一下,iOS 台设备可以读取随应用程序发送的文件。 经过一番研究,我发现这可能是编码问题。但是我在 SO 上尝试了此处提供的许多录音设置,但 none 有效。这是我用来录制音频文件的代码:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

    NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];

        [recordSettings NSNumber numberWithInt: kAudioFormatMPEG4AAC] forKey: AVFormatIDKey];
        [recordSettings setObject:[NSNumber numberWithFloat:16000.0] forKey: AVSampleRateKey];
        [recordSettings setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
        [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityMin] forKey: AVEncoderAudioQualityKey];

    }
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = paths[0];
    self.audioURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", basePath]];


    NSError *error = nil;
    self.audioRecorder = [[ AVAudioRecorder alloc] initWithURL:self.audioURL settings:recordSettings error:&error];

    if ([self.audioRecorder recordForDuration:60] == YES){
        [self.audioRecorder record];
    }

您能否告诉我我必须做出哪些更改才能使 Android 设备可以读取这些音频文件?

我可能会尝试使用 .aac 或 .mp4 而不是 .caf。

尝试从代码中删除 AVEncoderAudioQualityKey 并检查是否可以解决问题。还要检查您正在检查的 android 设备是否能够正确播放其他 aac 文件。

不,你不能说明所有使用的格式 Check here

您必须先转换为 AAC 或 WAV 才能使用它