简体   繁体   中英

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.

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.

Use this value offset :

0 < offset < lengthOfArray

so it will start reading from the current value of offset and hence write only the read data. Now you are using the value of offset = 0

auline.write(abData, 0, nBytesRead) --- > auline.write(abData, offset, nBytesRead)

where offset is greater than 0 but less than nBytesRead See the Doc #write(byte[], int, int)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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