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..681cd1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,12 @@
junit-jupiter-engine
${junit.version}
test
-
+
+
+ org.openjfx
+ javafx-media
+ 20
+
diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java
index c288d10..a2880e3 100644
--- a/src/main/java/sbu/javafx/Launcher.java
+++ b/src/main/java/sbu/javafx/Launcher.java
@@ -4,5 +4,7 @@ import javafx.application.Application;
public class Launcher{
public static void main(String[] args) {
+ Application.launch(MusicApp.class);
+ }
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
}
diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java
index a50badc..a890649 100644
--- a/src/main/java/sbu/javafx/MusicApp.java
+++ b/src/main/java/sbu/javafx/MusicApp.java
@@ -1,6 +1,7 @@
package sbu.javafx;
import javafx.application.Application;
+import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
@@ -8,7 +9,6 @@ import javafx.stage.Stage;
import java.io.IOException;
public class MusicApp extends Application {
-
@Override
public void start(Stage stage) throws IOException
{
diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java
index 5da27a9..c043b38 100644
--- a/src/main/java/sbu/javafx/MusicController.java
+++ b/src/main/java/sbu/javafx/MusicController.java
@@ -1,31 +1,127 @@
package sbu.javafx;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.event.ActionEvent;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
import javafx.scene.control.Label;
+import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
+import javafx.scene.media.Media;
+import javafx.scene.media.MediaPlayer;
+import javafx.stage.Stage;
+
+import java.io.File;
public class MusicController {
// TODO: Define your UI components using the @FXML annotation.
-
+ @FXML private Label nowPlayingLabel;
+ private Button currentlyPlayingButton = null;
+ private ObservableList playlistItems = FXCollections.observableArrayList();
+ private ListView playlistView = new ListView<>(playlistItems);
+ private Stage playlistStage = null;
+ private MediaPlayer mediaPlayer = null;
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
@FXML
- public void handlePlayAction() {
+ public void handlePlayAction(ActionEvent event) {
//Update labels, change button icons, etc.
+ Button clickedButton = (Button) event.getSource();
+ if(clickedButton == currentlyPlayingButton)
+ {
+ currentlyPlayingButton.setText("Play");
+ clickedButton.setStyle("-fx-background-color: #3498db; -fx-text-fill: white; -fx-background-radius: 3;"); // برگشت به رنگ آبی
+ nowPlayingLabel.setText("-");
+ currentlyPlayingButton = null;
+ if (mediaPlayer != null) {
+ mediaPlayer.stop();
+ }
+ }
+ else
+ {
+ if (currentlyPlayingButton != null)
+ {
+ currentlyPlayingButton.setText("Play");
+ currentlyPlayingButton.setStyle("-fx-background-color: #3498db; -fx-text-fill: white; -fx-background-radius: 3;");
+ if (mediaPlayer != null) {
+ mediaPlayer.stop();
+ }
+ }
+
+ clickedButton.setText("Stop");
+ clickedButton.setStyle("-fx-background-color: #e74c3c; -fx-text-fill: white; -fx-background-radius: 3;");
+ currentlyPlayingButton = clickedButton;
+ HBox hBox = (HBox) clickedButton.getParent();
+ String title = ((Label)hBox.getChildren().getFirst()).getText();
+ nowPlayingLabel.setText(title);
+ try {
+ String fileURI = getMusicFilePath(title); // گرفتن آدرس استاندارد فایل
+ Media media = new Media(fileURI); // گذاشتن نوار کاست
+ mediaPlayer = new MediaPlayer(media); // قراردادن در دستگاه پخش
+ mediaPlayer.play(); // 🚀 شروع پخش!
+ } catch (Exception e) {
+ System.out.println("Error playing file: " + e.getMessage());
+ // اگر فایلی پیدا نشد یا خطایی رخ داد، اینجا پرینت میشود تا برنامه کرش نکند
+ }
+ }
+
}
//TODO: Logic to add a specific song to the user's playlist.
-
- public void addToPlaylist(String songName) {
+ @FXML
+ public void addToPlaylist(ActionEvent event) {
//Add the song to a list or update a ListView.
+ Button clickedButton = (Button) event.getSource();
+ HBox row = (HBox) clickedButton.getParent();
+ Label songTitleLabel = (Label) row.getChildren().getFirst();
+ String songName = songTitleLabel.getText();
+ if(!playlistItems.contains(songName))
+ {
+ playlistItems.add(songName);
+ }
}
// TODO:This method should open a new window or change the current scene to display the "Playlist" page.
-
+ @FXML
public void openPlaylistWindow() {
//Create a new stage and show the playlist UI.
+ if (playlistStage != null && playlistStage.isShowing())
+ {
+ playlistStage.toFront();
+ return;
+ }
+ playlistStage = new Stage();
+ playlistStage.setTitle("My Playlist");
+ playlistView.setStyle(
+ "-fx-background-color: #ffffff; " +
+ "-fx-background-radius: 5; " +
+ "-fx-border-color: #dcdde1; " +
+ "-fx-border-width: 1; " +
+ "-fx-font-size: 14px; " +
+ "-fx-padding: 5;"
+ );
+ VBox root = new VBox(playlistView);
+ root.setStyle("-fx-background-color: #f5f5f5; -fx-padding: 15;");
+ VBox.setVgrow(playlistView, javafx.scene.layout.Priority.ALWAYS);
+ Scene scene = new Scene(root, 300, 400);
+ playlistStage.setScene(scene);
+ playlistStage.show();
}
+
+ private String getMusicFilePath(String songName) {
+ String fileName = switch (songName) {
+ case "Jana" -> "src\\main\\resources\\music\\Jana.mp3";
+ case "Jadoo" -> "src\\main\\resources\\music\\@RapRelease - Jadoo - Pidar.mp3";
+ case "we never dated" -> "src\\main\\resources\\music\\we never dated.mp3";
+ default -> "";
+ };
+ File file = new File(fileName);
+ return file.toURI().toString();
+ }
+
}
diff --git a/src/main/resources/music/@RapRelease - Jadoo - Pidar.mp3 b/src/main/resources/music/@RapRelease - Jadoo - Pidar.mp3
new file mode 100644
index 0000000..a0151fe
Binary files /dev/null and b/src/main/resources/music/@RapRelease - Jadoo - Pidar.mp3 differ
diff --git a/src/main/resources/music/Jana.mp3 b/src/main/resources/music/Jana.mp3
new file mode 100644
index 0000000..ff533c1
Binary files /dev/null and b/src/main/resources/music/Jana.mp3 differ
diff --git a/src/main/resources/music/we never dated.mp3 b/src/main/resources/music/we never dated.mp3
new file mode 100644
index 0000000..9c9a022
Binary files /dev/null and b/src/main/resources/music/we never dated.mp3 differ
diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml
index 306c8d3..b2a46c6 100644
--- a/src/main/resources/sbu/javafx/App-view.fxml
+++ b/src/main/resources/sbu/javafx/App-view.fxml
@@ -1,8 +1,76 @@
+
+
+
-
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file