How to recognize the audio stream format?

走远了吗. 提交于 2019-12-12 00:33:57

问题


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

回答1:


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:

  • 49 44 33 for MPEG-1 Audio Layer 3 (MP3) audio file
  • FF F1 for MPEG-4 Advanced Audio Coding (AAC) Low Complexity (LC) audio
  • FF F9 for MPEG-2 Advanced Audio Coding (AAC) Low Complexity (LC) audio


来源:https://stackoverflow.com/questions/18421736/how-to-recognize-the-audio-stream-format

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