简体   繁体   English

如何识别音频流格式?

[英]How to recognize the audio stream format?

Here I have the code which records a audio stream to file. 这里我有将音频流录制到文件的代码。 The problem is I'd like to save this file with correct file extension (mainly .mp3 and .aac). 问题是我想用正确的文件扩展名(主要是.mp3和.aac)保存这个文件。 How can I achieve this? 我怎样才能做到这一点?

URLConnection conn = new URL(StringUrls[0]).openConnection();
            InputStream in = conn.getInputStream();

            BufferedOutputStream bufOutstream = new BufferedOutputStream(new FileOutputStream(new File(env.getExternalStorageDirectory()+"/temp.file")));

            byte[] buffer = new byte[4096];
            int len = in.read(buffer);
            while (len != -1) {
                bufOutstream.write(buffer, 0, len);
                len = in.read(buffer);

                if (Recorder.this.isCancelled) break;

            }
            bufOutstream.close();

One way would be to take a look at the binary data while you already have it in your hands. 一种方法是在您掌握二进制数据的同时查看二进制数据。 According to this File signatures table both MP3 and AAC have unique magic headers: 根据这个文件签名表 ,MP3和AAC都有独特的魔术标题:

  • 49 44 33 for MPEG-1 Audio Layer 3 (MP3) audio file 49 44 33用于MPEG-1音频第3层(MP3)音频文件
  • FF F1 for MPEG-4 Advanced Audio Coding (AAC) Low Complexity (LC) audio FF F1用于MPEG-4高级音频编码(AAC)低复杂度(LC)音频
  • FF F9 for MPEG-2 Advanced Audio Coding (AAC) Low Complexity (LC) audio FF F9用于MPEG-2高级音频编码(AAC)低复杂度(LC)音频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM