Skip to content

Commit

Permalink
added functionality to set volume levels according to track genre
Browse files Browse the repository at this point in the history
  • Loading branch information
tayal007 authored Nov 12, 2016
1 parent b4243e7 commit c1231d2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/beatboxer/BeatBoxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void start(Stage stage) throws Exception {
state.addListener(new ChangeListener<String>(){
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
System.out.println(newValue);
if(newValue.equals("autoPlayNext")){
// playNext();
if(currentIndex==nowPlaying.size()-1){
Expand Down Expand Up @@ -98,16 +97,32 @@ public static void playNext(){
else{
currentIndex++;
BBSong song = nowPlaying.get(currentIndex);
System.out.println(song);
play(song);
}
}

private static double getvolumevalue(String genre) {
double volume;
if (genre.contains("Dance") || genre.contains("Party") || genre.contains("Rock") || genre.contains("Metal") || genre.contains("Progressive House")) {
volume = 1.0;
} else if (genre.contains("Pop") || genre.contains("Electro") || genre.contains("Techno") || genre.contains("Edm") || genre.contains("Hip hop") || genre.contains("Hip-hop") || genre.contains("Trap")) {
volume = 0.05;
} else if (genre.contains("Romantic") || genre.contains("Soothing") || genre.contains("Soul") || genre.contains("Piano") || genre.contains("Tropical House") || genre.contains("Ambient")) {
volume = 0.02;
} else if (genre.contains("Bollywood")) {
volume = 0.1;
} else {
volume = 0.3;
}
return volume;
}

public static void play(BBSong track){
mediaPlayer.dispose();
mediaPlayer = toMediaPlayer(track.getLocation());
initMediaPlayer();
currentIndex = BBGenerator.find(nowPlaying, track);
System.out.println("cI=" + currentIndex + track + " " + track.isFavourite());
mediaPlayer.setVolume(getvolumevalue(track.getGenre()));
mediaPlayer.play();
}
public static void initMediaPlayer(){
Expand Down Expand Up @@ -161,4 +176,4 @@ public static void main(String[] args) {
System.exit(0);
}

}
}

0 comments on commit c1231d2

Please sign in to comment.