diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/musics/random-artist1.mp3 b/musics/random-artist1.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/musics/something-artist2.mp3 b/musics/something-artist2.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/musics/test-artist3.mp3 b/musics/test-artist3.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml index e45147d..863ba02 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,8 @@ maven-compiler-plugin 3.13.0 - 23 - 23 + 21 + 21 diff --git a/src/main/java/sbu/javafx/Launcher.java b/src/main/java/sbu/javafx/Launcher.java index c288d10..e3e4a1d 100644 --- a/src/main/java/sbu/javafx/Launcher.java +++ b/src/main/java/sbu/javafx/Launcher.java @@ -2,7 +2,8 @@ package sbu.javafx; import javafx.application.Application; -public class Launcher{ +public class Launcher { public static void main(String[] args) { - // TODO: Launch the JavaFX application by calling Application.launch(Main.class) } -} + Application.launch(MusicApp.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/sbu/javafx/MusicApp.java b/src/main/java/sbu/javafx/MusicApp.java index a50badc..0ac846c 100644 --- a/src/main/java/sbu/javafx/MusicApp.java +++ b/src/main/java/sbu/javafx/MusicApp.java @@ -16,7 +16,6 @@ public class MusicApp extends Application { Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Music Player"); stage.setScene(scene); - //TODO: add icon to the stage stage.show(); } diff --git a/src/main/java/sbu/javafx/MusicController.java b/src/main/java/sbu/javafx/MusicController.java index 5da27a9..030fa60 100644 --- a/src/main/java/sbu/javafx/MusicController.java +++ b/src/main/java/sbu/javafx/MusicController.java @@ -1,31 +1,91 @@ package sbu.javafx; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.event.ActionEvent; +import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.ListView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.VBox; +import java.io.File; + public class MusicController { - // TODO: Define your UI components using the @FXML annotation. + @FXML Button playButton; + private boolean isPlaying = false; + @FXML private Label currentplaying; + @FXML private ListView musicListView; + private ObservableList musicList = FXCollections.observableArrayList(); + private ObservableList playList = FXCollections.observableArrayList(); - //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing. + @FXML + public void initialize() { + File folder = new File("musics"); + for (File file : folder.listFiles()) { + if (file.getName().endsWith(".mp3")) { + String[] str = file.getName().split("-"); + String songName = str[0]; + String artist = str[1]; + musicList.add(new Song(songName,artist,file.getAbsolutePath())); + } + } + + musicListView.setItems(musicList); + } @FXML public void handlePlayAction() { - //Update labels, change button icons, etc. + if (musicListView.getSelectionModel().getSelectedItem() != null) { + if (isPlaying) { + isPlaying = false; + playButton.setText("play"); + currentplaying.setText(""); + } else { + isPlaying = true; + playButton.setText("playing"); + currentplaying.setText("Now playing: " + musicListView.getSelectionModel().getSelectedItem().getSongName()); + } + } } - //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. + @FXML + public void handlePrevious() { + int currentIndex = musicListView.getSelectionModel().getSelectedIndex(); + if (currentIndex > 0) { + musicListView.getSelectionModel().select(currentIndex - 1); + isPlaying = false; + handlePlayAction(); + } } - // TODO:This method should open a new window or change the current scene to display the "Playlist" page. + @FXML + public void handlenext() { + int currentIndex = musicListView.getSelectionModel().getSelectedIndex(); + if (currentIndex < musicListView.getItems().size() - 1) { + musicListView.getSelectionModel().select(currentIndex + 1); + isPlaying = false; + handlePlayAction(); + } + } + @FXML + public void addToPlaylist() { + Song song = musicListView.getSelectionModel().getSelectedItem(); + if (song != null && !playList.contains(song)) { + playList.add(song); + } + } + + @FXML public void openPlaylistWindow() { - //Create a new stage and show the playlist UI. + musicListView.setItems(playList); + } + @FXML + public void openAllSongs() { + musicListView.setItems(musicList); } } diff --git a/src/main/java/sbu/javafx/Song.java b/src/main/java/sbu/javafx/Song.java new file mode 100644 index 0000000..b238803 --- /dev/null +++ b/src/main/java/sbu/javafx/Song.java @@ -0,0 +1,31 @@ +package sbu.javafx; + +public class Song { + private String songName; + private String artist; + private String songAddress; + + public Song(String songName, String artist, String songAddress) { + this.songName = songName; + this.artist = artist; + this.songAddress = songAddress; + } + + public String getSongName() { + return songName; + } + + public String getArtist() { + return artist; + } + + public String getSongAddress() { + return songAddress; + } + + @Override + public String toString() { + String result = getSongName() + " by " + getArtist(); + return result; + } +} diff --git a/src/main/resources/sbu/javafx/App-view.fxml b/src/main/resources/sbu/javafx/App-view.fxml index 306c8d3..1014caf 100644 --- a/src/main/resources/sbu/javafx/App-view.fxml +++ b/src/main/resources/sbu/javafx/App-view.fxml @@ -1,8 +1,33 @@ - - + + - + + + + + +
+ + + + + +
- + + +