I implemented the Play action and added the music files and song details.

This commit is contained in:
Matin
2026-05-30 02:28:25 +04:30
parent 2b5af885c9
commit 4a8f4d0f84
8 changed files with 135 additions and 24 deletions
+5
View File
@@ -14,6 +14,11 @@
<junit.version>5.10.2</junit.version> </properties> <junit.version>5.10.2</junit.version> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>21</version>
</dependency>
<dependency> <dependency>
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId> <artifactId>javafx-controls</artifactId>
+78 -4
View File
@@ -6,6 +6,10 @@ import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.fxml.FXML;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class MusicController { public class MusicController {
@@ -13,20 +17,90 @@ public class MusicController {
//TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.
public Button button ; private Button PlayButton ;
public void OnAction() private MediaPlayer mediaPlayer;
private boolean IsPlay = false ;
@FXML
public void Play( Button btn)
{ {
System.out.println("click on submit"); if (!IsPlay)
{
btn.setText("stop");
IsPlay = true ;
}
else if (IsPlay)
{
btn.setText("play");
IsPlay = false ;
}
} }
@FXML @FXML
public void handlePlayAction() { public void handlePlayAction(ActionEvent event) {
String songPath = "";
Button button =
(Button) event.getSource();
//Update labels, change button icons, etc. //Update labels, change button icons, etc.
if(button.getId().equals("1")) {
if (!IsPlay) {
songPath = "/1.mp3";
Play( button);
}
else
{
mediaPlayer.stop();
Play( button);
}
}
else if(button.getId().equals("2")) {
if (!IsPlay) {
songPath = "/2.mp3";
Play( button);
}
else
{
mediaPlayer.stop();
Play( button);
}
}
else if(button.getId().equals("3")) {
if (!IsPlay) {
songPath = "/3.mp3";
Play( button);
}
else
{
mediaPlayer.stop();
Play(button);
}
}
Media media = new Media(
getClass().getResource(songPath)
.toExternalForm()
);
mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();
} }
//TODO: Logic to add a specific song to the user's playlist. //TODO: Logic to add a specific song to the user's playlist.
public void addToPlaylist(String songName) { public void addToPlaylist(String songName) {
//Add the song to a list or update a ListView. //Add the song to a list or update a ListView.
} }
// TODO:This method should open a new window or change the current scene to display the "Playlist" page. // TODO:This method should open a new window or change the current scene to display the "Playlist" page.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

+50 -18
View File
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?> <?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<VBox alignment="CENTER" xmlns="http://javafx.com/javafx/26" xmlns:fx="http://javafx.com/fxml/1"> <VBox alignment="CENTER" xmlns="http://javafx.com/javafx/26" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sbu.javafx.MusicController">
<children> <children>
<Label alignment="CENTER" prefHeight="23.0" prefWidth="576.0" text="Music Player"> <Label alignment="CENTER" prefHeight="23.0" prefWidth="576.0" text="Music Player">
<font> <font>
@@ -31,28 +34,48 @@
<children> <children>
<AnchorPane prefHeight="65.0" prefWidth="578.0"> <AnchorPane prefHeight="65.0" prefWidth="578.0">
<children> <children>
<Label layoutX="32.0" layoutY="23.0" text="Song of Dawn" /> <Label layoutX="32.0" layoutY="23.0" text="Rahe Meykhaneh" />
<Label layoutX="169.0" layoutY="23.0" text="Alice" /> <Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
<Label layoutX="275.0" layoutY="23.0" text="03:45" /> <Label layoutX="275.0" layoutY="23.0" text="06:19" />
<Label layoutX="524.0" layoutY="23.0" text="Play" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" /> <Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button layoutX="366.0" layoutY="18.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="1" layoutX="520.0" layoutY="20.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>
</HBox> </HBox>
</children>
<HBox prefHeight="64.0" prefWidth="578.0"> <HBox prefHeight="64.0" prefWidth="578.0">
<children> <children>
<AnchorPane prefHeight="65.0" prefWidth="578.0"> <AnchorPane prefHeight="65.0" prefWidth="578.0">
<children> <children>
<Label layoutX="32.0" layoutY="23.0" text="Night Drive" /> <Label layoutX="32.0" layoutY="23.0" text="Saghi Bia" />
<Label layoutX="169.0" layoutY="23.0" text="John" /> <Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
<Label layoutX="275.0" layoutY="23.0" text="04:12" /> <Label layoutX="275.0" layoutY="23.0" text="01:52" />
<Label layoutX="524.0" layoutY="23.0" text="Play" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" /> <Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button layoutX="366.0" layoutY="19.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="2" layoutX="520.0" layoutY="21.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>
@@ -61,12 +84,21 @@
<children> <children>
<AnchorPane prefHeight="65.0" prefWidth="578.0"> <AnchorPane prefHeight="65.0" prefWidth="578.0">
<children> <children>
<Label layoutX="32.0" layoutY="23.0" text="Lost Sky" /> <Label layoutX="32.0" layoutY="23.0" text="Mara Be Hich Bedady" />
<Label layoutX="169.0" layoutY="23.0" text="Emma" /> <Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
<Label layoutX="275.0" layoutY="23.0" text="02:55" /> <Label layoutX="275.0" layoutY="23.0" text="16:59" />
<Label layoutX="524.0" layoutY="23.0" text="Play" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" /> <Rectangle arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="48.0" layoutX="7.0" layoutY="8.0" stroke="BLACK" strokeType="INSIDE" width="567.0" />
<Button layoutX="365.0" layoutY="18.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="86.0" text="Add To PlayList">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="3" layoutX="518.0" layoutY="20.0" mnemonicParsing="false" onAction="#handlePlayAction" prefHeight="22.0" prefWidth="34.0" text="Play">
<font>
<Font size="10.0" />
</font>
</Button>
</children> </children>
</AnchorPane> </AnchorPane>
@@ -83,5 +115,5 @@
</children> </children>
</HBox> </HBox>
</children>
</VBox> </VBox>