【问题标题】:Android recorded aac(.mp3) file not playing in iOSAndroid 录制的 aac(.mp3) 文件无法在 iOS 中播放
【发布时间】:2016-03-16 01:51:28
【问题描述】:

您好,我正在使用以下代码在 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) 中播放这个文件?

【问题讨论】:

  • 您的问题有点不清楚:mp3 录音在 iOS 和 Android 上都不能播放吗?
  • 您的问题与安卓或iOS有关
  • 嗨,我编辑了我的问题,添加了 swit 编码来播放

标签: android ios swift avplayer android-mediarecorder


【解决方案1】:

我得到的解决方案只是将扩展名更改为 .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")
}

【讨论】:

  • 我的文件存储在服务器中,它们是 .mp3 扩展名。可以设置 AVPlayer 将 mp3 文件视为 m4a 吗?
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • safari 不播放此 mp3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多