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)?
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")
}