2013-06-04 2 views
1

완벽하게 작동하는 음악 플레이어가 있지만 재생/일시 중지 단추를 추가하고 싶습니다. 버튼을 설정했는데 실제로는 클립을 일시 중지하는 코드를 모르겠습니다. 사전에클립을 일시 중지하려면 어떻게합니까? Java

 try{ 
     File f = new File("songs/mysong.wav"); 
     Clip clip = AudioSystem.getClip(); 
     AudioInputStream ais = AudioSystem.getAudioInputStream(f); 
     clip.open(ais); 
     playing = true; 
     if(MusicPlayer.pause) 
     { 
      clip.stop(); // <- Doesnt stop the song 
     } 
     clip.loop(Clip.LOOP_CONTINUOUSLY); 

    }catch(Exception exception){System.out.println("Failed To Play The WAV File!");} 

감사 :

여기 내 코드입니다!

답변

2

clip.open(ais) 다음에 clip.start();을 호출해야합니다. 그러면 clip.stop()이 작동합니다.

1

클립을 중지하기 전에 긴 변수를 할당하여 클립의 현재 시간 값을 가져옵니다. 예를 들어

:

long clipTime; 

clipTime= clip.getMicrosecondPostion(); 

clip.stop(); 

//When you want to resume the clip from the last position 

clip.setMicrosecondPosition(clipTime); 

clip.start(); 
관련 문제