从运行声音片段剪辑声音

时间:2011-10-04 14:51:58

标签: blackberry java-me

有人知道如何从运行声音文件中剪切声音片段吗?我正在开发一个黑莓应用程序,有人有任何示例代码或链接,请给我。

由于

此致 V辛格

2 个答案:

答案 0 :(得分:1)

可以剪切声音文件的一部分。你必须研究声音文件格式并处理声音文件二进制结构。

不,我没有示例代码,但您可以在研究声音文件格式后自行编写。

答案 1 :(得分:1)

//剪切声音文件(AMR)的示例代码

long startTime = player.getMediaTime(); long endTime = player.getMediaTime();

    private void cutByTimeDuration(long startTime, long endTime) {
    // TODO Auto-generated method stub
    byte[] byte1 = readDSoundFile("hello.amr"); //custom method original file 
    int noFramesStart = (int) (startTime / 20000);
    long noBytesStart = (noFramesStart * 32) + 6;
    int noFramesEnd = (int) (endTime / 20000);
    long noBytesEnd = (noFramesEnd * 32) + 6;
    byte[] byte2 = new byte[(int) (noBytesEnd - noBytesStart + 6)];
    System.arraycopy(byte1, 0, byte2, 0, 6);
    System.arraycopy(byte1, (int) noBytesStart, byte2, 6,
            (int) (noBytesEnd - noBytesStart));

    try {

        FileConnection file = (FileConnection) Connector.open(filePath
                + "/" + "xyz.amr", Connector.READ_WRITE);
        if (file.exists())
            file.delete();

        // if (!file.exists() )
        {
            file.create();
            OutputStream out = file.openOutputStream();
            int length = byte2.length;// -1;
            out.write(byte2, 0, length);
            Thread.yield();

            out.flush();
            out.close();
            file.close();

        }
    } catch (Exception e) {
    }

}
相关问题