4 Commits
Author SHA1 Message Date
ArefeRoosta 853e489e4c complete playlist 2026-05-28 00:00:28 +03:30
ArefeRoosta e9c10e5ad3 complete the main page 2026-05-27 23:59:56 +03:30
ArefeRoosta d454e7d6fa add and complete Song class 2026-05-27 23:57:54 +03:30
ArefeRoosta deab89e066 add required files (songs and icon) 2026-05-27 23:57:03 +03:30
16 changed files with 420 additions and 16 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

+16 -2
View File
@@ -17,12 +17,26 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.6</version>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.6</version>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>de.codecentric.centerdevice</groupId>
<artifactId>javafxsvg</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+4 -1
View File
@@ -4,5 +4,8 @@ import javafx.application.Application;
public class Launcher{
public static void main(String[] args) {
// TODO: Launch the JavaFX application by calling Application.launch(Main.class) }
Application.launch(MusicApp.class);
}
}
//the icon is not displayed
+23
View File
@@ -1,22 +1,45 @@
package sbu.javafx;
import de.codecentric.centerdevice.javafxsvg.SvgImageLoaderFactory;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javafx.scene.image.Image;
public class MusicApp extends Application {
@Override
public void start(Stage stage) throws IOException
{
// SvgImageLoaderFactory.install();
// InputStream iconStream = getClass().getResourceAsStream("icon.svg");
// if (iconStream != null)
// {
// Image icon = new Image(iconStream);
// stage.getIcons().add(icon);
// System.out.println("yesss");
// } else
// {
// System.out.println("not found");
// }
FXMLLoader fxmlLoader = new FXMLLoader(MusicApp.class.getResource("App-view.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("Music Player");
stage.setScene(scene);
//TODO: add icon to the stage
// InputStream iconStream = new FileInputStream("musicIcon.png");
// if (iconStream != null)
// {
// stage.getIcons().add(new Image(iconStream));
// } else {
// System.out.println("not found");
// }
stage.show();
}
+162 -10
View File
@@ -2,30 +2,182 @@ package sbu.javafx;
import javafx.fxml.FXML;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javax.imageio.IIOException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class MusicController {
// TODO: Define your UI components using the @FXML annotation.
@FXML private Label nowPlayingSong;
@FXML private Button playBtn1;
@FXML private Button playBtn2;
@FXML private Button playBtn3;
@FXML private Button playBtn4;
@FXML private Button add1;
@FXML private Button add2;
@FXML private Button add3;
@FXML private Button add4;
private List<Song> playlist = new ArrayList<>();
private Song currentSong = null;
private MediaPlayer mediaPlayer;
private Song song1 = new Song("The Comfort of a Laugh Track", "Roar", "04:52", "songs/song1.mp3");
private Song song2 = new Song("Perfect Day", "Lou Reed", "03:44", "songs/song2.mp3");
private Song song3 = new Song("Wish You Were Here", "Pink Floyd", "05:34", "songs/song3.mp3");
private Song song4 = new Song("No Surprises", "Radiohead", "03:49", "songs/song4.mp3");
//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() {
//Update labels, change button icons, etc.
public void handlePlayAction(ActionEvent event) {
Button clickedBotton = (Button) event.getSource();
resetPlayButtons();
String buttonId = clickedBotton.getId();
switch (buttonId)
{
case "playBtn1":
playSong(song1);
playBtn1.setText("Playing");
playBtn1.setStyle("-fx-pref-width: 120; -fx-font-size: 20px; -fx-background-color: lightBlue;");
break;
case "playBtn2":
playSong(song2);
playBtn2.setText("Playing");
playBtn2.setStyle("-fx-pref-width: 120; -fx-font-size: 20px; -fx-background-color: lightBlue;");
break;
case "playBtn3":
playSong(song3);
playBtn3.setText("Playing");
playBtn3.setStyle("-fx-pref-width: 120; -fx-font-size: 20px; -fx-background-color: lightBlue;");
break;
case "playBtn4":
playSong(song4);
playBtn4.setText("Playing");
playBtn4.setStyle("-fx-pref-width: 120; -fx-font-size: 20px; -fx-background-color: lightBlue;");
break;
}
}
//TODO: Logic to add a specific song to the user's playlist.
@FXML
public void addToPlaylist(ActionEvent event) {
public void addToPlaylist(String songName) {
//Add the song to a list or update a ListView.
Button clickedButton = (Button) event.getSource();
String btnId = clickedButton.getId();
Song selectedSong = null;
switch (btnId)
{
case "add1":
selectedSong = song1;
break;
case "add2":
selectedSong = song2;
break;
case "add3":
selectedSong = song3;
break;
case "add4":
selectedSong = song4;
break;
}
if (selectedSong != null)
{
playlist.add(selectedSong);
}
}
// 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.
try
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("playlist.fxml"));
Parent root = loader.load();
PlaylistController playlistController = loader.getController();
playlistController.setPlaylist(playlist, this);
Stage playlistStage = new Stage();
playlistStage.setTitle("Playlist");
playlistStage.setScene(new Scene(root, 500, 400));
playlistStage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
public void playSong(Song song) {
if (mediaPlayer != null)
{
mediaPlayer.stop();
mediaPlayer.dispose();
}
try {
File musicFile = new File(song.getFilePath());
if (!musicFile.exists()) {
nowPlayingSong.setText("Error: File not found - " + song.getFilePath());
System.out.println("Not found: " + musicFile.getAbsolutePath());
return;
}
Media media = new Media(musicFile.toURI().toString());
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
resetPlayButtons();
nowPlayingSong.setStyle("-fx-font-weight: bold; -fx-font-size: 20px;");
nowPlayingSong.setText("-");
if (mediaPlayer != null)
{
mediaPlayer.dispose();
mediaPlayer = null;
}
}
});
mediaPlayer.play();
currentSong = song;
nowPlayingSong.setStyle("-fx-font-size: 20px;");
nowPlayingSong.setText(song.getTitle() + " - " + song.getArtist());
} catch (Exception e) {
nowPlayingSong.setText("Playback error");
e.printStackTrace();
}
}
public void resetPlayButtons()
{
playBtn1.setText("Play");
playBtn1.setStyle("-fx-pref-width: 120; -fx-font-size: 20px;");
playBtn2.setText("Play");
playBtn2.setStyle("-fx-pref-width: 120; -fx-font-size: 20px;");
playBtn3.setText("Play");
playBtn3.setStyle("-fx-pref-width: 120; -fx-font-size: 20px;");
playBtn4.setText("Play");
playBtn4.setStyle("-fx-pref-width: 120; -fx-font-size: 20px;");
}
}
@@ -0,0 +1,67 @@
package sbu.javafx;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import java.util.ArrayList;
import java.util.List;
public class PlaylistController {
@FXML
private VBox songContainer;
private ArrayList<Song> playlist;
private MusicController musicController;
public void setPlaylist(List<Song> playlist, MusicController musicController)
{
this.playlist = new ArrayList<> (playlist);
this.musicController = musicController;
buildRows();
}
public void buildRows()
{
songContainer.getChildren().clear();
for (Song s : playlist)
{
HBox hbox = new HBox(20); //spacing = 20
hbox.setAlignment(javafx.geometry.Pos.CENTER);
Label nameLabel = new Label(s.getDisplayName());
nameLabel.setPrefWidth(250);
Label durationLabel = new Label(s.getDuration());
Button playBtn = new Button("Play");
playBtn.setPrefWidth(80);
playBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
if (musicController != null) {
musicController.playSong(s);
}
}
});
hbox.getChildren().addAll(nameLabel, durationLabel, playBtn);
songContainer.getChildren().add(hbox);
}
if (playlist.isEmpty()) {
Label emptyLabel = new Label("Playlist is empty. Add some songs from the main page.");
emptyLabel.setStyle("-fx-text-fill: gray;");
songContainer.getChildren().add(emptyLabel);
}
}
}
+53
View File
@@ -0,0 +1,53 @@
package sbu.javafx;
public class Song {
private String title;
private String artist;
private String duration;
private String filePath;
public Song(String title, String artist, String duration, String filePath)
{
this.filePath = filePath;
this.artist = artist;
this.duration = duration;
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getDisplayName()
{
return getTitle()+" - " + getArtist();
}
}
+70 -2
View File
@@ -1,8 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/fxml" alignment="CENTER" spacing="10">
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Button?>
<VBox xmlns="http://javafx.com/fxml" xmlns:fx ="http://javafx.com/fxml" fx:controller="sbu.javafx.MusicController" alignment="TOP_CENTER" spacing="10" style="-fx-padding: 60">
<Label text="Music Player" style="-fx-font-size: 40px; -fx-font-weight: bold;"/>
<Separator/>
<!--songs-->
<VBox spacing="5" alignment="CENTER" style="-fx-padding: 0 0 5 0;">
<HBox spacing="20" alignment="CENTER">
<Label text="Song Title" style="-fx-font-weight: bold; -fx-pref-width: 290; -fx-font-size: 20px"/>
<Label text="Artist Name" style="-fx-font-weight: bold; -fx-pref-width: 150; -fx-font-size: 20px;"/>
<Label text="Duration" style="-fx-font-weight: bold; -fx-pref-width: 90; -fx-font-size: 20px"/>
<Label alignment="CENTER" text="Add to Playlist" style="-fx-font-weight: bold; -fx-pref-width: 150; -fx-font-size: 20px"/>
<Label alignment="CENTER" text="Play" style="-fx-font-weight: bold; -fx-pref-width: 120; -fx-font-size: 20px"/>
</HBox>
<Separator/>
<!--song1-->
<HBox spacing="20" alignment="CENTER">
<Label text="The Comfort of a Laugh Track" style="-fx-pref-width: 290; -fx-font-size: 20px;"/>
<Label text="Roar" style="-fx-pref-width: 150; -fx-font-size: 20px;"/>
<Label text="04:52" style="-fx-pref-width: 90; -fx-font-size: 20px;"/>
<Button fx:id="add1" text="Add to Playlist" style="-fx-pref-width: 150; -fx-font-size: 19px;" onAction="#addToPlaylist"/>
<Button fx:id="playBtn1" text="Play" style="-fx-pref-width: 120; -fx-font-size: 20px;" onAction="#handlePlayAction"/>
</HBox>
<!--song2-->
<HBox spacing="20" alignment="CENTER">
<Label text="Perfect Day" style="-fx-pref-width: 290; -fx-font-size: 20px;"/>
<Label text="Lou Reed" style="-fx-pref-width: 150; -fx-font-size: 20px;"/>
<Label text="03:44" style="-fx-pref-width: 90; -fx-font-size: 20px;"/>
<Button fx:id="add2" text="Add to Playlist" style="-fx-pref-width: 150; -fx-font-size: 19px;" onAction="#addToPlaylist"/>
<Button fx:id="playBtn2" text="Play" style="-fx-pref-width: 120; -fx-font-size: 20px;" onAction="#handlePlayAction"/>
</HBox>
<!--song3-->
<HBox spacing="20" alignment="CENTER">
<Label text="Wish You Were Here" style="-fx-pref-width: 290; -fx-font-size: 20px;"/>
<Label text="Pink Floyd" style="-fx-pref-width: 150; -fx-font-size: 20px;"/>
<Label text="05:34" style="-fx-pref-width: 90; -fx-font-size: 20px;"/>
<Button fx:id="add3" text="Add to Playlist" style="-fx-pref-width: 150; -fx-font-size: 19px;" onAction="#addToPlaylist"/>
<Button fx:id="playBtn3" text="Play" style="-fx-pref-width: 120; -fx-font-size: 20px;" onAction="#handlePlayAction"/>
</HBox>
<!--song4-->
<HBox spacing="20" alignment="CENTER">
<Label text="No Surprises" style="-fx-pref-width: 290; -fx-font-size: 20px;"/>
<Label text="Radiohead" style="-fx-pref-width: 150; -fx-font-size: 20px;"/>
<Label text="03:49" style="-fx-pref-width: 90; -fx-font-size: 20px;"/>
<Button fx:id="add4" text="Add to Playlist" style="-fx-pref-width: 150; -fx-font-size: 19px;" onAction="#addToPlaylist"/>
<Button fx:id="playBtn4" text="Play" style="-fx-pref-width: 120; -fx-font-size: 20px;" onAction="#handlePlayAction"/>
</HBox>
</VBox>
<Separator/>
<HBox style="-fx-border-color: lightBlue; -fx-border-width: 5; -fx-padding: 10; -fx-pref-width: 400;" spacing="10" alignment="CENTER_LEFT">
<HBox>
<Label text="Now Playing: " style="-fx-font-weight: bold; -fx-font-size: 20px;"/>
<Label fx:id="nowPlayingSong" text="-" style="-fx-font-weight: bold; -fx-font-size: 20px;"/>
</HBox>
<HBox alignment="CENTER_RIGHT" HBox.hgrow="ALWAYS">
<Button text="Open Playlist" style="-fx-pref-width: 120; -fx-font-size: 15px;" onAction="#openPlaylistWindow"/>
</HBox>
</HBox>
<!-- TODO: Add your code here! -->
</VBox>
+4
View File
@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="64" height="64">
<circle cx="12" cy="12" r="10" fill="#1DB954" stroke="#ffffff" stroke-width="1.5"/>
<polygon points="10,8 16,12 10,16" fill="#ffffff"/>
</svg>

After

Width:  |  Height:  |  Size: 230 B

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="sbu.javafx.PlaylistController"
spacing="10" alignment="CENTER" style="-fx-padding: 20;">
<Label text="Your Playlist" style="-fx-font-size: 30px; -fx-font-weight: bold;"/>
<VBox fx:id="songContainer" spacing="5" alignment="CENTER"/>
</VBox>
<!--future feature: remove from playlist-->