[A]How to make a MP3 repeat in javafx?

后端 未结 2 668
梦如初夏
梦如初夏 2021-01-05 10:00

i want my mp3 file repeat again after it finished . but i\'m unable to create a loop to play my file repeatedly (i used this code but only it plays first second of my file a

相关标签:
2条回答
  • 2021-01-05 10:36

    for avoiding the suddenly stopping, you must :

    a.setOnReady(new Runnable() {
            @Override
            public void run() {
                a.play();
            }
        });
    

    It works for me.

    0 讨论(0)
  • 2021-01-05 10:41

    i found my solution i used setOnEndOfMedia method :

     URL resource = getClass().getResource("abcd.mp3");
     MediaPlayer a =new MediaPlayer(new Media(resource.toString()));
     a.setOnEndOfMedia(new Runnable() {
           public void run() {
             a.seek(Duration.ZERO);
           }
       });
      a.play();
    
    0 讨论(0)
提交回复
热议问题