Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart clip from the beginning after stopping it?

Tags:

java

audio

Clip clip;
clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(sound));

I mean, how to start playing clip always from the beginning. When I stop it in the middle and then start it again, it plays from the middle and that's what I do not want.

like image 977
Tomáš Kratochvíl Avatar asked Dec 31 '16 15:12

Tomáš Kratochvíl


1 Answers

Call clip.setMicrosecondPosition(0) before playing the clip again. This will reset the current position. https://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/Clip.html#setMicrosecondPosition(long)

like image 103
J. Tennié Avatar answered Sep 21 '22 07:09

J. Tennié