diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index fd7b85b..92f3ac6 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -14,6 +14,7 @@ public class MusicApp extends Application { { FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml")); Scene scene = new Scene(fxmlLoader.load()); + stage.setTitle("Music Player"); stage.setScene(scene); diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 98596b8..18aa2cb 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -2,17 +2,71 @@ package sbu.javafx; import javafx.fxml.FXML; import javafx.event.ActionEvent; -import javafx.scene.control.Button; -import javafx.scene.control.Label; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; import javafx.scene.input.MouseEvent; import javafx.scene.layout.VBox; import javafx.fxml.FXML; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; +import javafx.scene.control.ListView; +import javafx.stage.Stage; +import javafx.scene.control.Slider; +import javafx.scene.control.Label; +import javafx.util.Duration; +import javafx.scene.control.ToggleButton; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Objects; public class MusicController { + ArrayList playls = new ArrayList<>() ; + @FXML + private ListView playlistview ; + @FXML + private Label nowPlayingLabel ; + @FXML + private Slider timeSlider ; + @FXML + private Label timeLabel ; + @FXML + private Slider volumeSlider ; + @FXML + private ToggleButton themeButton ; + @FXML + public void toggleTheme() { + + Scene scene = themeButton.getScene(); + + scene.getStylesheets().clear(); + + if(themeButton.isSelected()) { + + scene.getStylesheets().add( + getClass() + .getResource("dark-theme.css") + .toExternalForm() + ); + + themeButton.setText("Dark Mode"); + } + else { + + scene.getStylesheets().add( + getClass() + .getResource("light-theme.css") + .toExternalForm() + ); + + themeButton.setText("Light Mode"); + } + } + // TODO: Define your UI components using the @FXML annotation. //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. @@ -26,12 +80,14 @@ public class MusicController { if (!IsPlay) { btn.setText("stop"); + IsPlay = true ; } else if (IsPlay) { btn.setText("play"); + IsPlay = false ; } } @@ -45,12 +101,14 @@ public class MusicController { if (!IsPlay) { songPath = "/1.mp3"; Play( button); + nowPlayingLabel.setText("Rahe Meykhaneh"); } else { mediaPlayer.stop(); Play( button); + nowPlayingLabel.setText("Stop"); @@ -62,12 +120,14 @@ public class MusicController { if (!IsPlay) { songPath = "/2.mp3"; Play( button); + nowPlayingLabel.setText("Saghi Bia"); } else { mediaPlayer.stop(); Play( button); + nowPlayingLabel.setText("Stop"); } } @@ -78,11 +138,14 @@ public class MusicController { songPath = "/3.mp3"; Play( button); + nowPlayingLabel.setText("Mara Be Hich Bedady"); + } else { mediaPlayer.stop(); Play(button); + nowPlayingLabel.setText("Stop"); } } @@ -93,19 +156,91 @@ public class MusicController { ); mediaPlayer = new MediaPlayer(media); + mediaPlayer.setVolume( + volumeSlider.getValue() / 100.0 + ); + volumeSlider.valueProperty().addListener( + (obs, oldVal, newVal) -> { + + if(mediaPlayer != null) { + + mediaPlayer.setVolume( + newVal.doubleValue() / 100.0 + ); + + } + } + ); + mediaPlayer.setOnReady(() -> { + + timeSlider.setMax(mediaPlayer.getTotalDuration().toSeconds()); + }); + mediaPlayer.currentTimeProperty().addListener( + (obs, oldTime, newTime) -> { + + timeSlider.setValue( + newTime.toSeconds() + ); + timeLabel.setText( + (int)newTime.toMinutes() + + ":" + + (int)(newTime.toSeconds() % 60) + ); + + } + ); + timeSlider.setOnMouseReleased(event2 -> { + + mediaPlayer.seek( + Duration.seconds( + timeSlider.getValue() + ) + ); + + }); + mediaPlayer.play(); } //TODO: Logic to add a specific song to the user's playlist. - public void addToPlaylist(String songName) { + public void addToPlaylist( ActionEvent event) { //Add the song to a list or update a ListView. - + Button button = + (Button) event.getSource(); + if(!playls.contains(button.getUserData().toString())) { + playls.add(button.getUserData().toString()); + } + System.out.println(playls); + } // TODO:This method should open a new window or change the current scene to display the "Playlist" page. - - public void openPlaylistWindow() { + @FXML + public void openPlaylistWindow () throws IOException { //Create a new stage and show the playlist UI. + System.out.println("Button Clicked"); + System.out.println( + getClass().getResource("App-view2.fxml") + ); + FXMLLoader loader = new FXMLLoader( + getClass().getResource("App-view2.fxml") + ); + Parent root = loader.load(); + MusicController controller = loader.getController(); + + controller.playlistview.getItems().addAll(playls); + + Stage stage = new Stage() ; + + + stage.setTitle("Playlist"); + + stage.setScene(new Scene(root)); + + stage.show(); + + + playlistview.getItems().addAll(playls) ; } } diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 7fbf0bc..2c4f921 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -2,14 +2,15 @@ + + - +