diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..8306744
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index e45147d..5fdf03f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,11 @@
5.10.2
+
+ org.openjfx
+ javafx-media
+ 21
+
org.openjfx
javafx-controls
diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java
index c288d10..2a7323a 100644
--- a/src/main/java/sbu/javafx/Launcher.java
+++ b/src/main/java/sbu/javafx/Launcher.java
@@ -2,7 +2,13 @@ package sbu.javafx;
import javafx.application.Application;
-public class Launcher{
+public class Launcher {
+
public static void main(String[] args) {
- // TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
+
+ Application.launch(MusicApp.class ,args);
+
+
+ }
}
+
diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java
index a50badc..92f3ac6 100644
--- a/src/main/java/sbu/javafx/MusicApp.java
+++ b/src/main/java/sbu/javafx/MusicApp.java
@@ -14,8 +14,10 @@ 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);
+
//TODO: add icon to the stage
stage.show();
}
diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java
index 5da27a9..18aa2cb 100644
--- a/src/main/java/sbu/javafx/MusicController.java
+++ b/src/main/java/sbu/javafx/MusicController.java
@@ -2,30 +2,245 @@ package sbu.javafx;
import javafx.fxml.FXML;
import javafx.event.ActionEvent;
-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.
+ private Button PlayButton ;
+ private MediaPlayer mediaPlayer;
+ private boolean IsPlay = false ;
@FXML
- public void handlePlayAction() {
- //Update labels, change button icons, etc.
+ public void Play( Button btn)
+ {
+ if (!IsPlay)
+ {
+ btn.setText("stop");
+
+ IsPlay = true ;
+
+ }
+ else if (IsPlay)
+ {
+ btn.setText("play");
+
+ IsPlay = false ;
+ }
}
+ @FXML
+ public void handlePlayAction(ActionEvent event) {
+ String songPath = "";
+ Button button =
+ (Button) event.getSource();
+ //Update labels, change button icons, etc.
+ if(button.getId().equals("1")) {
+ if (!IsPlay) {
+ songPath = "/1.mp3";
+ Play( button);
+ nowPlayingLabel.setText("Rahe Meykhaneh");
+
+ }
+ else
+ {
+ mediaPlayer.stop();
+ Play( button);
+ nowPlayingLabel.setText("Stop");
+
+
+
+ }
+ }
+
+ else if(button.getId().equals("2")) {
+
+ if (!IsPlay) {
+ songPath = "/2.mp3";
+ Play( button);
+ nowPlayingLabel.setText("Saghi Bia");
+
+ }
+ else
+ {
+ mediaPlayer.stop();
+ Play( button);
+ nowPlayingLabel.setText("Stop");
+
+ }
+ }
+
+ else if(button.getId().equals("3")) {
+
+ if (!IsPlay) {
+ songPath = "/3.mp3";
+ Play( button);
+
+ nowPlayingLabel.setText("Mara Be Hich Bedady");
+
+ }
+ else
+ {
+ mediaPlayer.stop();
+ Play(button);
+ nowPlayingLabel.setText("Stop");
+
+ }
+ }
+
+ Media media = new Media(
+ getClass().getResource(songPath)
+ .toExternalForm()
+ );
+
+ 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/1.mp3 b/src/main/resources/1.mp3
new file mode 100644
index 0000000..27df216
Binary files /dev/null and b/src/main/resources/1.mp3 differ
diff --git a/src/main/resources/2.mp3 b/src/main/resources/2.mp3
new file mode 100644
index 0000000..735f818
Binary files /dev/null and b/src/main/resources/2.mp3 differ
diff --git a/src/main/resources/3.mp3 b/src/main/resources/3.mp3
new file mode 100644
index 0000000..9f416e3
Binary files /dev/null and b/src/main/resources/3.mp3 differ
diff --git a/src/main/resources/AlbumArtSmall.jpg b/src/main/resources/AlbumArtSmall.jpg
new file mode 100644
index 0000000..f88f72b
Binary files /dev/null and b/src/main/resources/AlbumArtSmall.jpg differ
diff --git a/src/main/resources/Folder.jpg b/src/main/resources/Folder.jpg
new file mode 100644
index 0000000..117b86b
Binary files /dev/null and b/src/main/resources/Folder.jpg differ
diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml
index 306c8d3..2c4f921 100644
--- a/src/main/resources/sbu/javafx/App-view.fxml
+++ b/src/main/resources/sbu/javafx/App-view.fxml
@@ -1,8 +1,141 @@
+
+
+
+
+
+
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/sbu/javafx/App-view2.fxml b/src/main/resources/sbu/javafx/App-view2.fxml
new file mode 100644
index 0000000..bc7fe18
--- /dev/null
+++ b/src/main/resources/sbu/javafx/App-view2.fxml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/sbu/javafx/dark-theme.css b/src/main/resources/sbu/javafx/dark-theme.css
new file mode 100644
index 0000000..927331f
--- /dev/null
+++ b/src/main/resources/sbu/javafx/dark-theme.css
@@ -0,0 +1,20 @@
+.root {
+ -fx-background-color: #1e1e1e;
+}
+
+.label {
+ -fx-text-fill: white;
+}
+
+.button {
+ -fx-background-color: #333333;
+ -fx-text-fill: white;
+}
+
+.list-view {
+ -fx-background-color: #2b2b2b;
+}
+
+.slider {
+ -fx-control-inner-background: #333333;
+}
\ No newline at end of file