I implemented the Play action and added the music files and song details.
This commit is contained in:
@@ -14,6 +14,11 @@
|
||||
<junit.version>5.10.2</junit.version> </properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-media</artifactId>
|
||||
<version>21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
|
||||
@@ -6,6 +6,10 @@ import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
|
||||
|
||||
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.
|
||||
|
||||
public Button button ;
|
||||
public void OnAction()
|
||||
private Button PlayButton ;
|
||||
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
|
||||
public void handlePlayAction() {
|
||||
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);
|
||||
|
||||
}
|
||||
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.
|
||||
|
||||
public void addToPlaylist(String songName) {
|
||||
//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.
|
||||
|
||||
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 |
@@ -1,12 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?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>
|
||||
<Label alignment="CENTER" prefHeight="23.0" prefWidth="576.0" text="Music Player">
|
||||
<font>
|
||||
@@ -31,28 +34,48 @@
|
||||
<children>
|
||||
<AnchorPane prefHeight="65.0" prefWidth="578.0">
|
||||
<children>
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Song of Dawn" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="Alice" />
|
||||
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
|
||||
<Label layoutX="275.0" layoutY="23.0" text="03:45" />
|
||||
<Label layoutX="524.0" layoutY="23.0" text="Play" />
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Rahe Meykhaneh" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
|
||||
|
||||
<Label layoutX="275.0" layoutY="23.0" text="06:19" />
|
||||
|
||||
<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>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
|
||||
<HBox prefHeight="64.0" prefWidth="578.0">
|
||||
<children>
|
||||
<AnchorPane prefHeight="65.0" prefWidth="578.0">
|
||||
<children>
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Night Drive" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="John" />
|
||||
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
|
||||
<Label layoutX="275.0" layoutY="23.0" text="04:12" />
|
||||
<Label layoutX="524.0" layoutY="23.0" text="Play" />
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Saghi Bia" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
|
||||
|
||||
<Label layoutX="275.0" layoutY="23.0" text="01:52" />
|
||||
|
||||
<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>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
@@ -61,12 +84,21 @@
|
||||
<children>
|
||||
<AnchorPane prefHeight="65.0" prefWidth="578.0">
|
||||
<children>
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Lost Sky" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="Emma" />
|
||||
<Label layoutX="376.0" layoutY="23.0" text="Add To Playlist" />
|
||||
<Label layoutX="275.0" layoutY="23.0" text="02:55" />
|
||||
<Label layoutX="524.0" layoutY="23.0" text="Play" />
|
||||
<Label layoutX="32.0" layoutY="23.0" text="Mara Be Hich Bedady" />
|
||||
<Label layoutX="169.0" layoutY="23.0" text="M.Shajarian" />
|
||||
|
||||
<Label layoutX="275.0" layoutY="23.0" text="16:59" />
|
||||
<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>
|
||||
</AnchorPane>
|
||||
@@ -83,5 +115,5 @@
|
||||
</children>
|
||||
</HBox>
|
||||
|
||||
|
||||
</children>
|
||||
</VBox>
|
||||
|
||||
Reference in New Issue
Block a user