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

编程入门 行业动态 更新时间:2024-10-26 10:29:04
本文介绍了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中播放

本文发布于:2023-11-23 15:39:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   aac   Android   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!