Created
January 12, 2018 16:44
-
-
Save davisonio/4c4112a14c54708adf02689a9ba4954c to your computer and use it in GitHub Desktop.
JavaFX Music Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/* CODE AT TOP OF CLASS SO THAT MEDIA PLAYER IS ACCESSIBLE EVERYWHERE */* | |
public static MediaPlayer songPlayer = null; | |
*/* CODE TO START PLAYING */* | |
File songFile = new File("Music/amazingsong.mp3"); // Music folder | |
should be in project root, not in 'src' | |
if (songFile.isFile()) { | |
Media songMedia = new Media(songFile.toURI().toString()); | |
songPlayer = new MediaPlayer(songMedia); | |
songPlayer.play(); | |
} else { | |
System.out.println("File error."); | |
} | |
*/* CODE TO PAUSE */* | |
if (songPlayer != null) { | |
songPlayer.pause(); | |
} | |
*/* CODE TO CHANGE VOLUME */* | |
if (songPlayer != null) { | |
songPlayer.setVolume(0.5); // Set volume to 50% | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment