Android录制的aac(.mp3)文件未在iOS中播放 [英] Android recorded aac(.mp3) file not playing in iOS

查看:405
本文介绍了Android录制的aac(.mp3)文件未在iOS中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在Android上录制音频

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");

}

,但是该aac(.mp3)文件无法在iOS上播放. 编辑

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()

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

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

推荐答案

我得到的解决方案只是将扩展名更改为.m4a,因此可以在ios上运行

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

这篇关于Android录制的aac(.mp3)文件未在iOS中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆