Search code examples
javaaudioplaybackseekjavasound

Play and Seek Audio File in java


I used this class to play my Wav file.

Its very good but How to start my wav file on some position (KB or second)?

auline.start();
    int nBytesRead = 0;
    byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];



    try {
        while (nBytesRead != -1) {
            nBytesRead = audioInputStream.read(abData, 0, abData.length);
            System.out.println("s");
            if (nBytesRead >= 0)
                auline.write(abData, 0, nBytesRead);
        }
    } catch (IOException e) {
        return;
    } finally {
        auline.drain();
        auline.close();
    }

This is part of the code.


Solution

  • A Clip(1) makes it easy to start a sound from wherever is needed (in seconds). For an example see the Clip code in the JavaSound info. page.

    1. See especially.