Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public static void playMusic(){
  2. media = new Media("file:///" + System.getProperty("user.dir").replace('\', '/') + "/" + "ressource/audio/tetris_1.mp3");
  3. MediaPlayer player = new MediaPlayer(media);// I will declare media and player it as a static variable later
  4. player.setAutoPlay(true);
  5. player.play();
  6. player.setOnEndOfMedia(new Runnable() {
  7. public void run() {
  8. player.seek(Duration.ZERO);
  9. }
  10. });
  11. // Create Handlers for handling Errors (copy-pasted code)
  12. player.setOnError(new Runnable()
  13. {
  14. public void run()
  15. {
  16. System.out.println(player.getError());
  17. }
  18. });
  19.  
  20. media.setOnError(new Runnable()
  21. {
  22. public void run()
  23. {
  24. System.out.println(media.getError());
  25. }
  26. });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement