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

偶尔善良 提交于 2019-12-12 14:27:22

问题


Hi I'm using the following code to record audio on 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");

}

but that aac(.mp3) file does not play on iOS. EDIT

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

How do I play this file in IOS(Swift)?


回答1:


i got solution just changed extension to .m4a it work on 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")
}



回答2:


myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); suggests you should have been writing to mp4 (m4a). Not sure aac can be written to mp3 container




回答3:


check if you can play that file in safari of iPhone. and can you tell how are you trying to play that file?



来源:https://stackoverflow.com/questions/34201702/android-recorded-aac-mp3-file-not-playing-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!