I am writing an audio player. I need to add a rewind function for 10 seconds forward and backward. How to do it?
Here is example:
public static void main(String[] args) {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream("file.wav");
} catch (UnsupportedAudioFileException | IOException e1) {
e1.printStackTrace();
}
try {
Clip clip = clip = AudioSystem.getClip();
} catch (LineUnavailableException e2) {
e2.printStackTrace();
}
try {
clip.open(ais);
} catch (LineUnavailableException | IOException e1) {
e1.printStackTrace();
}
}
private static forward(){
//code here
}
private static backwards(){
//code here
}
Sorry for bad code :p
CodePudding user response:
Have you tried the setFramePosition
or setMicrosecondPosition
method of the clip?
https://docs.oracle.com/javase/8/docs/api/javax/sound/sampled/Clip.html#setFramePosition-int-