Android 录制的 aac(.mp3) 文件无法在 iOS 中播放

Android recorded aac(.mp3) file not playing in iOS

您好,我正在使用以下代码在 Android

上录制音频
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
myRecorder.setAudioSamplingRate(44100);
myRecorder.setAudioEncodingBitRate(256);
myRecorder.setAudioChannels(1);
voiceFileName = getFilename();
myRecorder.setOutputFile(voiceFileName);

private String getFilename() {
    String filepath = Environment.getExternalStorageDirectory().getPath();
    File file = new File(filepath, "test");

    if (!file.exists()) {
        file.mkdirs();
    }
    return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp3");

}

但是那个 aac(.mp3) 文件不能在 iOS 上播放。 编辑

let audioFilename = getDocumentsDirectory().stringByAppendingPathComponent("whistle.mp3")
let audioURL = NSURL(fileURLWithPath: audioFilename)
let whistlePlayer:AVAudioplayer = try AVAudioPlayer(contentsOfURL: audioURL)
whistlePlayer.play()

如何在 IOS(Swift) 中播放此文件?

检查您是否可以在 iPhone 的 safari 中播放该文件。 你能告诉我你是如何尝试播放那个文件的吗?

我得到解决方案只是将扩展名更改为 .m4a 它适用于 ios

let audioFilename = getDocumentsDirectory().stringByAppendingPathComponent("voice.m4a")
let audioURL = NSURL(fileURLWithPath: audioFilename)
do
 {
   audioPlayer = try AVAudioPlayer(contentsOfURL: audioURL)
   audioPlayer.delegate = self
   audioPlayer.play()
 }
catch{
   print("filenotfound")
}

myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);建议您应该一直写入 mp4 (m4a)。不确定 aac 是否可以写入 mp3 容器