adding buttons repeat and mute
@@ -18,18 +18,27 @@ public class Main extends Application {
|
||||
controller.musicsListView.getItems().addAll(
|
||||
new Song("Blinding Lights", "The Weeknd"),
|
||||
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);
|
||||
|
||||
Scene scene = new Scene(root, 600, 500);
|
||||
Scene scene = new Scene(root, 500, 600);
|
||||
scene.getStylesheets().add(
|
||||
getClass().getResource("/css/light.css").toExternalForm()
|
||||
);
|
||||
|
||||
primaryStage.setTitle("Music Player");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package sbu.javafx;
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.Duration;
|
||||
|
||||
|
||||
public class MusicController {
|
||||
@@ -28,14 +27,21 @@ public class MusicController {
|
||||
@FXML
|
||||
Button playPauseBtn;
|
||||
@FXML
|
||||
Button audioBtn;
|
||||
@FXML
|
||||
Button openPlaylistBtn;
|
||||
@FXML
|
||||
Button themeToggleBtn;
|
||||
@FXML
|
||||
private Label messageLabel;
|
||||
private boolean isDarkMode=true;
|
||||
private boolean isPlaying=false;
|
||||
private boolean isMute=false;
|
||||
private Song currentSong = null;
|
||||
ImageView playIcon;
|
||||
ImageView pauseIcon;
|
||||
ImageView audioIcon;
|
||||
ImageView muteIcon;
|
||||
|
||||
// TODO: Define your UI components using the @FXML annotation.
|
||||
|
||||
@@ -43,14 +49,22 @@ public class MusicController {
|
||||
public void initialize() {
|
||||
Image playImg = new Image(getClass().getResourceAsStream("/image/play.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);
|
||||
pauseIcon = new ImageView(pauseImg);
|
||||
audioIcon= new ImageView(audioImg);
|
||||
muteIcon= new ImageView(muteImg);
|
||||
|
||||
playIcon.setFitWidth(35);
|
||||
playIcon.setFitHeight(35);
|
||||
pauseIcon.setFitWidth(35);
|
||||
pauseIcon.setFitHeight(35);
|
||||
audioIcon.setFitWidth(35);
|
||||
audioIcon.setFitHeight(35);
|
||||
muteIcon.setFitWidth(35);
|
||||
muteIcon.setFitHeight(35);
|
||||
|
||||
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.
|
||||
|
||||
public void addToPlaylist(ActionEvent event, Song song) {
|
||||
//Add the song to a list or update a ListView.
|
||||
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.
|
||||
@@ -183,8 +218,15 @@ public class MusicController {
|
||||
musicsListView.setVisible(false);
|
||||
if(playlistListView!=null)
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@ public class Song {
|
||||
this.singer=singer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " ";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -18,14 +18,19 @@
|
||||
<Region HBox.hgrow="ALWAYS" /> <!-- این فضا رو پر میکنه تا دکمه سمت چپ بمونه -->
|
||||
</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" />
|
||||
@@ -33,12 +38,23 @@
|
||||
<!-- دکمههای جلو عقب -->
|
||||
<HBox alignment="CENTER" spacing="20">
|
||||
|
||||
<Button fx:id="prevButton"
|
||||
<Button fx:id="audioBtn"
|
||||
onAction="#mute"
|
||||
styleClass="circle-button">
|
||||
|
||||
<graphic>
|
||||
<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>
|
||||
</graphic>
|
||||
</Button>
|
||||
@@ -56,12 +72,22 @@
|
||||
</Button>
|
||||
|
||||
|
||||
<Button fx:id="nextButton"
|
||||
<Button fx:id="nextBtn"
|
||||
styleClass="circle-button">
|
||||
|
||||
<graphic>
|
||||
<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>
|
||||
</graphic>
|
||||
</Button>
|
||||
|
||||