작은 wav 사운드를 재생하는 간단한 Clip 메서드가 있습니다. 그래, 지금은 메서드 clip.loop()를 발견하지만, 어쨌든 나는 왜 내 메서드 isnt 작업을 이해할 수 없다.java 클립 루프가 작동하지 않습니다.
을 Heres 코드 :
public void playSound(final String sound, final boolean loop, final int repeatTime){
try {
sounds.get(sound).open();
}
catch(Exception e) {
System.out.println(e);
}
new Thread(new Runnable() {
public void run() {
int repeatCount = 1;
Clip actualClip = sounds.get(sound);
actualClip.setFramePosition(0);
actualClip.start();
while(true){
System.out.println("repeat c: " + repeatCount + ", frames left: " + (actualClip.getFrameLength() - actualClip.getFramePosition()));
if(actualClip.getFramePosition() >= actualClip.getFrameLength()){
actualClip.stop();
actualClip.setFramePosition(0);
actualClip.start();
repeatCount++;
}
if(!loop && repeatCount > repeatTime){
break;
}
}
actualClip.stop();
}
}).start();
}
의 스트링 사운드, 메신저 becaus는 해시 맵에서 그것을 받고. 전화 할 때
playSound(key, false, 10);
사운드가 10 회 반복됩니다. 하지만 다시 전화 할 때 (버튼 하나로), 4 ~ 8 번 연주하기 때문에 루프가 제대로 작동하지 않습니다. 무슨 일이야?
감사합니다.
1) 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. 2)'Clip '은 별도의'Thread'를 필요로하지 않습니다. –
'if (! loop || repeatCount> repeatTime)'이어야한다고 생각합니다. BTW,'while' 대신'for'를 사용하지 않으시겠습니까? 코드를 훨씬 쉽게 읽을 수 있습니다. – Elist
고마워요 ... 그게 사실 sscce o.O ok 실패 ... 정말해야합니다. – GFP