用于播放MP3文件的Java,javazoom程序(AdvancedPlayer),event.getFrame()正在给出随机的东西

时间:2015-01-27 19:17:40

标签: java

我试图编写播放.mp3文件的程序,播放它们非常有效。但暂停导致一些麻烦。当我暂停歌曲(停止播放歌曲并询问帧)时,我得到的值不正确。

class PauseStartMP3Test {
private static  AdvancedPlayer player;
private static int pausedOnFrame = 0;
private static boolean playing = false;


public static void main(String[] args) {
Scanner in = new Scanner(System.in);        
while(true) {
    String s = in.next();
    if(!s.equals("")) {
    if(!playing) {                  
        playing = true;
        play();
    }
    else {
        player.stop();
    }
    }
}

}

public static void play() {
File file = null;
    file = new File("C:\\Users\\Remco\\Desktop\\Programming\\musictest/throughglass.mp3");   
    try {
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);

        try {

          player = new AdvancedPlayer(bis);
          new Thread() {
              public void run() {
                  try { 
          if(playing) {
            player.setPlayBackListener(new PlaybackListener()  {
            @Override                 
            public void playbackFinished(PlaybackEvent event) {     
                pausedOnFrame = event.getFrame();       
                System.out.println(pausedOnFrame); 
                playing = false;
            }
            }); 
            player.play(pausedOnFrame, Integer.MAX_VALUE);
          }
          else {
              player.stop();
          }
          }
                  catch (Exception e) {
                      System.out.println(e);
                  }
              }
          }.start();

        } catch (JavaLayerException ex) {
            System.out.println(ex);
        }

    } catch (FileNotFoundException ex) {
        System.out.println(ex);
    }    


}

0 个答案:

没有答案