使用AmrInputStream将PCM编码的wav文件转换为amr文件,但无法使用MediaPlayer播放它

发布于 2024-12-23 03:53:03 字数 458 浏览 7 评论 0原文

我正在使用 AmrInputStream 将 PCM 编码的 wav 文件转换为 Android 中的 amr 文件。我使用了下面帖子中的代码:

使用 AmrInputStream 将 PCM-16 转换为 AMR

一切正常,amr 文件也是生成的。然而,当我尝试用 MeidaPlayer 播放它时,它抛出了以下异常:

   java.io.IOException: Prepare failed.: status=0xFFFFFFFC  
      at android.media.MediaPlayer.prepare(Native Method)

我注意到在上面的帖子中,它提到:“需要将 #AMR!\n 标签添加到输出文件中进行播放。”。但我不知道到底该怎么做。请帮忙!

I am converting a PCM encoded wav file to amr file in Android using AmrInputStream. I used the code from below post:

converting PCM-16 to AMR using AmrInputStream

Everything works fine, and the amr file is also generated. However, when I tried to play it with MeidaPlayer, it thrown following exception:

   java.io.IOException: Prepare failed.: status=0xFFFFFFFC  
      at android.media.MediaPlayer.prepare(Native Method)

I noticed that in the above post, it mentioned: "requiring adding the #AMR!\n tag to the output file for playing.". but I don't know how to do it exactly. Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的韩爷 2024-12-30 03:53:03

好的,我成功了。需要在输出文件的前6个字节中添加标签:

    InputStream inStream;
    inStream = new FileInputStream(wavFilename);
    AmrInputStream aStream = new AmrInputStream(inStream);

    File file = new File(amrFilename);        
    file.createNewFile();
    OutputStream out = new FileOutputStream(file); 

    out.write(0x23);
    out.write(0x21);
    out.write(0x41);
    out.write(0x4D);
    out.write(0x52);
    out.write(0x0A);    

    byte[] x = new byte[1024];
    int len;
    while ((len=aStream.read(x)) > 0) {
        out.write(x,0,len);
    }

    out.close();

Ok, I made it working. need to add the tag in the first 6 bytes of the output file:

    InputStream inStream;
    inStream = new FileInputStream(wavFilename);
    AmrInputStream aStream = new AmrInputStream(inStream);

    File file = new File(amrFilename);        
    file.createNewFile();
    OutputStream out = new FileOutputStream(file); 

    out.write(0x23);
    out.write(0x21);
    out.write(0x41);
    out.write(0x4D);
    out.write(0x52);
    out.write(0x0A);    

    byte[] x = new byte[1024];
    int len;
    while ((len=aStream.read(x)) > 0) {
        out.write(x,0,len);
    }

    out.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文