adding buttons repeat and mute

This commit is contained in:
2026-05-28 16:44:10 +03:30
parent dc60e5954f
commit ef31487a02
11 changed files with 97 additions and 15 deletions
+11 -2
View File
@@ -18,18 +18,27 @@ public class Main extends Application {
controller.musicsListView.getItems().addAll( controller.musicsListView.getItems().addAll(
new Song("Blinding Lights", "The Weeknd"), new Song("Blinding Lights", "The Weeknd"),
new Song("Flowers", "Miley Cyrus"), new Song("Flowers", "Miley Cyrus"),
new Song("As It Was", "Harry Styles") new Song("As It Was", "Harry Styles"),
new Song("Comme des enfants", "Coert De Pirate"),
new Song("Slow Down", "GRAE"),
new Song("Cigarettes out the window", "TV Girl"),
new Song("Shape of My Heart", "Sting"),
new Song("deja vu", "Olivia Rodirgo"),
new Song("Do It To It", "Acraze"),
new Song("Bones", "Imagine Dragons"),
new Song("Bunker", "Balthazar")
); );
controller.setupListView(controller.musicsListView); controller.setupListView(controller.musicsListView);
Scene scene = new Scene(root, 600, 500); Scene scene = new Scene(root, 500, 600);
scene.getStylesheets().add( scene.getStylesheets().add(
getClass().getResource("/css/light.css").toExternalForm() getClass().getResource("/css/light.css").toExternalForm()
); );
primaryStage.setTitle("Music Player"); primaryStage.setTitle("Music Player");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show(); primaryStage.show();
} }
+48 -6
View File
@@ -1,18 +1,17 @@
package sbu.javafx; package sbu.javafx;
import javafx.animation.PauseTransition;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.control.Button; import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.util.Duration;
public class MusicController { public class MusicController {
@@ -28,14 +27,21 @@ public class MusicController {
@FXML @FXML
Button playPauseBtn; Button playPauseBtn;
@FXML @FXML
Button audioBtn;
@FXML
Button openPlaylistBtn; Button openPlaylistBtn;
@FXML @FXML
Button themeToggleBtn; Button themeToggleBtn;
@FXML
private Label messageLabel;
private boolean isDarkMode=true; private boolean isDarkMode=true;
private boolean isPlaying=false; private boolean isPlaying=false;
private boolean isMute=false;
private Song currentSong = null; private Song currentSong = null;
ImageView playIcon; ImageView playIcon;
ImageView pauseIcon; ImageView pauseIcon;
ImageView audioIcon;
ImageView muteIcon;
// TODO: Define your UI components using the @FXML annotation. // TODO: Define your UI components using the @FXML annotation.
@@ -43,14 +49,22 @@ public class MusicController {
public void initialize() { public void initialize() {
Image playImg = new Image(getClass().getResourceAsStream("/image/play.png")); Image playImg = new Image(getClass().getResourceAsStream("/image/play.png"));
Image pauseImg = new Image(getClass().getResourceAsStream("/image/pause.png")); Image pauseImg = new Image(getClass().getResourceAsStream("/image/pause.png"));
Image audioImg= new Image(getClass().getResourceAsStream("/image/icons8-audio-64.png"));
Image muteImg= new Image(getClass().getResourceAsStream("/image/icons8-mute-64.png"));
playIcon = new ImageView(playImg); playIcon = new ImageView(playImg);
pauseIcon = new ImageView(pauseImg); pauseIcon = new ImageView(pauseImg);
audioIcon= new ImageView(audioImg);
muteIcon= new ImageView(muteImg);
playIcon.setFitWidth(35); playIcon.setFitWidth(35);
playIcon.setFitHeight(35); playIcon.setFitHeight(35);
pauseIcon.setFitWidth(35); pauseIcon.setFitWidth(35);
pauseIcon.setFitHeight(35); pauseIcon.setFitHeight(35);
audioIcon.setFitWidth(35);
audioIcon.setFitHeight(35);
muteIcon.setFitWidth(35);
muteIcon.setFitHeight(35);
playPauseBtn.setGraphic(playIcon); playPauseBtn.setGraphic(playIcon);
@@ -169,11 +183,32 @@ public class MusicController {
} }
} }
@FXML
public void mute(ActionEvent e){
isMute=!isMute;
if(isMute){
audioBtn.setGraphic(audioIcon);
}else{
audioBtn.setGraphic(muteIcon);
}
}
//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(ActionEvent event, Song song) { public void addToPlaylist(ActionEvent event, Song song) {
//Add the song to a list or update a ListView. //Add the song to a list or update a ListView.
playlistListView.getItems().add(song); playlistListView.getItems().add(song);
messageLabel.setText("Added to playlist!");
messageLabel.setVisible(true);
PauseTransition pause = new PauseTransition(Duration.seconds(2));
pause.setOnFinished(e -> {
messageLabel.setVisible(false);
});
pause.play();
} }
// 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.
@@ -183,8 +218,15 @@ public class MusicController {
musicsListView.setVisible(false); musicsListView.setVisible(false);
if(playlistListView!=null) if(playlistListView!=null)
playlistListView.setVisible(true); playlistListView.setVisible(true);
else
throw new RuntimeException("Playlist is empty"); else{
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Empty Playlist");
alert.setHeaderText(null);
alert.setContentText("Playlist is empty!");
alert.showAndWait();
}
} }
} }
+5
View File
@@ -9,6 +9,11 @@ public class Song {
this.singer=singer; this.singer=singer;
} }
@Override
public String toString() {
return " ";
}
public String getName() { public String getName() {
return name; return name;
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

+33 -7
View File
@@ -18,14 +18,19 @@
<Region HBox.hgrow="ALWAYS" /> <!-- این فضا رو پر میکنه تا دکمه سمت چپ بمونه --> <Region HBox.hgrow="ALWAYS" /> <!-- این فضا رو پر میکنه تا دکمه سمت چپ بمونه -->
</HBox> </HBox>
<Label fx:id="messageLabel"
textFill="green"
visible="false"/>
<!--آهنگ های موجود --> <!--آهنگ های موجود -->
<ListView fx:id="musicsListView" prefHeight="400" /> <ListView fx:id="musicsListView" VBox.vgrow="ALWAYS"/>
<!-- آهنگ های پلی لیست--> <!-- آهنگ های پلی لیست-->
<ListView fx:id="playlistListView" prefHeight="400" /> <ListView fx:id="playlistListView" visible="false"
managed="false" VBox.vgrow="ALWAYS"/>
<!-- باکس آهنگ در حال پخش --> <!-- باکس آهنگ در حال پخش -->
<VBox alignment="CENTER" spacing="10"> <VBox alignment="CENTER" spacing="5">
<!-- اسم آهنگ در حال پخش --> <!-- اسم آهنگ در حال پخش -->
<Label fx:id="nowPlayingLabel" style="-fx-font-weight: bold; -fx-font-size: 14px;" text="No song playing" /> <Label fx:id="nowPlayingLabel" style="-fx-font-weight: bold; -fx-font-size: 14px;" text="No song playing" />
@@ -33,12 +38,23 @@
<!-- دکمه‌های جلو عقب --> <!-- دکمه‌های جلو عقب -->
<HBox alignment="CENTER" spacing="20"> <HBox alignment="CENTER" spacing="20">
<Button fx:id="prevButton" <Button fx:id="audioBtn"
onAction="#mute"
styleClass="circle-button"> styleClass="circle-button">
<graphic> <graphic>
<ImageView fitWidth="35" fitHeight="35"> <ImageView fitWidth="35" fitHeight="35">
<Image url="/image/rewind.png" /> <Image url="/image/icons8-audio-64.png" />
</ImageView>
</graphic>
</Button>
<Button fx:id="preveBtn"
styleClass="circle-button">
<graphic>
<ImageView fitWidth="35" fitHeight="35">
<Image url="/image/icons8-skip-to-start-64.png" />
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
@@ -56,12 +72,22 @@
</Button> </Button>
<Button fx:id="nextButton" <Button fx:id="nextBtn"
styleClass="circle-button"> styleClass="circle-button">
<graphic> <graphic>
<ImageView fitWidth="35" fitHeight="35"> <ImageView fitWidth="35" fitHeight="35">
<Image url="/image/forward.png" /> <Image url="/image/icons8-end-64.png" />
</ImageView>
</graphic>
</Button>
<Button fx:id="repeat"
styleClass="circle-button">
<graphic>
<ImageView fitWidth="35" fitHeight="35">
<Image url="/image/icons8-synchronize-64.png" />
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>