1

I am creating an application to play an audio file (WAV). Playback works out perfectly, I did a small feature to make a forward "leap" of X (seconds) via the skip() method of audioInputStream and this also works perfectly.

My problem is to achieve the backward "leap" X (seconds). I use again the skip() method with a negative number, it works. But then the audio file doesn't read the end of the file I am losing the X (seconds) at the end, my playback stops and my reference audioInputStream.read returns -1 as if my playback was finished but it actually did not.

Johan
  • 74,508
  • 24
  • 191
  • 319
Laurent F.
  • 23
  • 8
  • can you post some code? – gpasch Jan 25 '16 at 16:07
  • You may find [this](http://stackoverflow.com/questions/1267488/play-wav-file-backward) answer helpful. – Drew Lemmy Jan 25 '16 at 16:08
  • Thank you for your answers. But the code of the given page fully loads the audio file before you start making the above treatment . For small audio file that does not pose a problem but for larger files , the processing time will be too big. – Laurent F. Jan 29 '16 at 06:54

1 Answers1

1

Here are a sample of my code :

while ((((bytesRead = this.audioInputStream.read(audioDataFull, 0, audioDataFull.length)) != -1) && (!this.leaveThread))) {
     line.write(audioDataFull, 0, bytesRead);
     this.nb++;
     while (this.audioWav.isPause()) {
        if (test) {
           try {
              this.audioInputStream.skip((long) -(this.audioInputStream.getFormat().getSampleRate()
                    * (this.audioInputStream.getFormat().getSampleSizeInBits() / 8) * TraitementXML.tmpXml.getBufferRelecture()));
              test = false;
           } catch (final Exception e) {
              this.audioInputStream.skip(-(this.nb * bytesRead));
              this.nb = 0;
              test = false;
           }
        }
        try {
           Thread.sleep(1000);
        } catch (final InterruptedException e) {
           logger.error(e.getMessage(), e);
        }
     }
  }
Laurent F.
  • 23
  • 8