Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

towards the end.. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/Controller$1.class
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/Controller$2.class
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/Controller$3.class
Binary file not shown.
Binary file removed out/production/MusicPlayer/main/Controller$4.class
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/Controller.class
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/MediaList.class
Binary file not shown.
Binary file modified out/production/MusicPlayer/main/resources/images/headlines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
11 changes: 8 additions & 3 deletions out/production/MusicPlayer/main/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<Image url="@resources/images/play.png" />
</image>
</ImageView>
<ImageView id="pause" fx:id="pause" fitHeight="22.0" fitWidth="32.0" layoutX="154.0" layoutY="492.0" onMouseClicked="#playClickAction">
<image>
<Image url="@resources/images/pause.png" />
</image>
</ImageView>
<ImageView fx:id="next" fitHeight="28.0" fitWidth="28.0" layoutX="216.0" layoutY="489.0" onMouseClicked="#nextClickEvent">
<image>
<Image url="@resources/images/rightarrow.png" />
Expand All @@ -28,7 +33,7 @@
<Image url="@resources/images/leftarrow.png" />
</image>
</ImageView>
<ImageView fx:id="menu" fitHeight="28.0" fitWidth="28.0" layoutX="14.0" layoutY="14.0" onMouseClicked="#menuClickEvent">
<ImageView fx:id="menu" fitHeight="24.0" fitWidth="22.0" layoutX="20.0" layoutY="16.0" onMouseClicked="#menuClickEvent">
<image>
<Image url="@resources/images/headlines.png" />
</image>
Expand Down Expand Up @@ -60,8 +65,8 @@
</children>
</Pane>
<JFXSlider fx:id="slider" layoutX="73.0" layoutY="534.0" prefHeight="24.0" prefWidth="192.0" style="-jfx-default-track: #659AB1; -jfx-default-thumb: #F2C75C" value="0.0" />
<Label fx:id="totalTime" alignment="CENTER" layoutX="266.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="Label" />
<Label fx:id="curnTime" alignment="CENTER" layoutX="11.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="Label" />
<Label fx:id="totalTime" alignment="CENTER" layoutX="266.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="00:00" />
<Label fx:id="curnTime" alignment="CENTER" layoutX="11.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="00:00" />
</children></AnchorPane>
</children>
</AnchorPane>
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/main/.DS_Store
Binary file not shown.
120 changes: 57 additions & 63 deletions src/main/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.ImageView;
Expand All @@ -29,6 +30,7 @@

public class Controller implements Initializable {

@FXML private ImageView pause;
@FXML private Label totalTime;
@FXML private Label curnTime;
@FXML private JFXSlider slider;
Expand All @@ -43,8 +45,6 @@ public class Controller implements Initializable {
@FXML private ImageView bubble;
@FXML private ProgressBar progress;
@FXML private Label message;
@FXML private Label info;
@FXML private MediaView mv;

private MediaPlayer mp;
private Media me;
Expand All @@ -53,29 +53,23 @@ public class Controller implements Initializable {
private String songName = "";
private String songPath = "";
private MediaList mediaList = null;
private String path = "/Users/velox/Desktop/MusicPlayer/src/main/resources/media/L2-5.mp4";

private Duration duration;
private static final double MIN_CHANGE = 0.5 ;
private final boolean repeat = false;
private boolean stopRequested = false;
private boolean atEndOfMedia = false;
private Label playTime;
private Timer timer;
private TimerTask timerTask;




@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
try {
bubble.setVisible(false);
me = new Media(new File(path).toURI().toString());
mp = new MediaPlayer(me);
mp.play();
duration = mp.getMedia().getDuration();
setListeners();
pause.setVisible(false);
//me = new Media(new File(path).toURI().toString());
//mp = new MediaPlayer(me);
//mp.play();
//duration = mp.getMedia().getDuration();
//setListeners();
}
catch (Exception e) {
System.out.println("error occurred");
Expand All @@ -95,10 +89,9 @@ public void invalidated(Observable ov) {
@Override
public void changed(ObservableValue<? extends Duration> observableValue, Duration duration, Duration t1) {
if (!slider.isValueChanging())
slider.setValue(t1.toSeconds() / mp.getTotalDuration().toSeconds() * 100);
slider.setValue((double)(t1.toSeconds()) / (double) (mp.getTotalDuration().toSeconds()) * 100.0);
totalTime.setText(formatTime(mp.getTotalDuration().toSeconds()));
curnTime.setText(formatTime(t1.toSeconds()));
System.out.println(totalTime.getText());
}
});

Expand Down Expand Up @@ -147,11 +140,13 @@ public String formatInt(int num) {
}



public void duckClickEvent(MouseEvent mouseEvent) {
bubble.setVisible(!displaying);
displaying = !displaying;
}


// import songs by clicking on menu icon
public void menuClickEvent(MouseEvent mouseEvent) {
try {
Expand All @@ -160,8 +155,8 @@ public void menuClickEvent(MouseEvent mouseEvent) {
Stage stage = (Stage) background.getScene().getWindow();
File selectedDirec = direcChooser.showDialog(stage);
if (selectedDirec != null) {
System.out.println(selectedDirec.getName());
mediaList = new MediaList(selectedDirec);
playSong(0);
}
else {
System.out.println("WARNING: no directory selected.");
Expand All @@ -172,44 +167,8 @@ public void menuClickEvent(MouseEvent mouseEvent) {
}
}

public boolean setupSong() {
// here the mediaList is already setup
songName = mediaList.getSongName();
songPath = mediaList.getSongPath();

if (songPath.equals("") || songName.equals("")) return false;

me = new Media(songPath);
mp = new MediaPlayer(me);

mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);

mp.setOnEndOfMedia(new Runnable() {
public void run() {
stopRequested = true;
atEndOfMedia = true;
System.out.println("end of media reached");
}
});

duration = mp.getMedia().getDuration();
setListeners();
message.setText("Playing: " + songName);
return true;
}

public void playSong(int indChange) {
mp.stop();
sliderClock(false);

if (mediaList == null) {
AlertWindow aw = new AlertWindow();
aw.display("Error", "No song selected");
return;
}

mediaList.changeCurnInd(indChange);
if (!setupSong()) {
public void playNullError(int indChange) {
if (songPath.equals("") || songName.equals("")) {
String message;
switch (indChange) {
case -1:
Expand All @@ -227,37 +186,72 @@ public void playSong(int indChange) {
}
AlertWindow aw = new AlertWindow();
aw.display("Error", message);
}
}

public void playSong(int indChange) {
if (mediaList == null) {
AlertWindow aw = new AlertWindow();
aw.display("Error", "No song selected");
return;
}
// if (mp != null) { mp.stop(); }

mediaList.changeCurnInd(indChange);

songName = mediaList.getSongName();
songPath = mediaList.getSongPath();

if (songPath.equals("") || songName.equals("")) {
playNullError(indChange);
mediaList.changeCurnInd(-1 * indChange);
return;
}
else {
// mp.setAutoPlay(false);
mp.play();
sliderClock(true);
playing = true;
System.out.println(mp.getStatus());
else if (indChange != 0 || mp == null) {
if (mp != null) { mp.stop(); }
me = new Media(songPath);
mp = new MediaPlayer(me);
duration = mp.getMedia().getDuration();
// System.out.println(duration);
setListeners();
}
message.setText("Playing: " + songName);
// sliderClock(true);
mp.play();
playing = true;
}

public void playClickAction(MouseEvent mouseEvent) {
if (playing) {
mp.pause();
play.setVisible(false);
pause.setVisible(true);
message.setText("Paused: " + songName);
playing = false;
sliderClock(false);
// sliderClock(false);
}
else {
play.setVisible(true);
pause.setVisible(false);
playSong(0);
}
}

public void nextClickEvent(MouseEvent mouseEvent) {
playSong(1);
play.setVisible(true);
pause.setVisible(false);
playSong(1);
}

public void previousClickEvent(MouseEvent mouseEvent) {
play.setVisible(true);
pause.setVisible(false);
playSong(-1);
}




public void closeClickEvent(MouseEvent mouseEvent) {
ConfirmWindow cw = new ConfirmWindow();
boolean choice = cw.display("Confirm Exit", "Do you want to exit?");
Expand Down
10 changes: 3 additions & 7 deletions src/main/MediaList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public MediaList(File selectedDirec) {
File [] files = selectedDirec.listFiles();
for (File f : files) {
String filePath = f.getAbsolutePath();
if (filePath.endsWith(".mp3") || filePath.endsWith(".mp4") || filePath.endsWith(".wav")) {
if (filePath.endsWith(".mp3") || filePath.endsWith(".mp4") || filePath.endsWith(".wav")
|| filePath.endsWith(".m4a") || filePath.endsWith(".m4v")) {
mediaList.add(f);
}
}
Expand Down Expand Up @@ -51,8 +52,6 @@ public String getSongName() {

public String getSongPath() {
if (testValidity()) {
System.out.println(curnInd);
System.out.println(mediaList.size());
return mediaList.get(curnInd).toURI().toString();
}
return "";
Expand All @@ -63,9 +62,6 @@ public void changeCurnInd(int indChange) {
}

public boolean testValidity() {
if (curnInd < mediaList.size() && curnInd >= 0) {
return true;
}
return false;
return (curnInd < mediaList.size() && curnInd >= 0);
}
}
Binary file modified src/main/resources/.DS_Store
Binary file not shown.
Binary file added src/main/resources/images/.DS_Store
Binary file not shown.
Binary file modified src/main/resources/images/headlines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 0 additions & 70 deletions src/main/resources/media/K.mp3

This file was deleted.

Binary file removed src/main/resources/media/K.wav
Binary file not shown.
Binary file removed src/main/resources/media/L2-5.mp4
Binary file not shown.
Binary file removed src/main/resources/media/Mystery of Love.mp3
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/media/sea.m4a
Binary file not shown.
11 changes: 8 additions & 3 deletions src/main/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<Image url="@resources/images/play.png" />
</image>
</ImageView>
<ImageView id="pause" fx:id="pause" fitHeight="22.0" fitWidth="32.0" layoutX="154.0" layoutY="492.0" onMouseClicked="#playClickAction">
<image>
<Image url="@resources/images/pause.png" />
</image>
</ImageView>
<ImageView fx:id="next" fitHeight="28.0" fitWidth="28.0" layoutX="216.0" layoutY="489.0" onMouseClicked="#nextClickEvent">
<image>
<Image url="@resources/images/rightarrow.png" />
Expand All @@ -28,7 +33,7 @@
<Image url="@resources/images/leftarrow.png" />
</image>
</ImageView>
<ImageView fx:id="menu" fitHeight="28.0" fitWidth="28.0" layoutX="14.0" layoutY="14.0" onMouseClicked="#menuClickEvent">
<ImageView fx:id="menu" fitHeight="24.0" fitWidth="22.0" layoutX="20.0" layoutY="16.0" onMouseClicked="#menuClickEvent">
<image>
<Image url="@resources/images/headlines.png" />
</image>
Expand Down Expand Up @@ -60,8 +65,8 @@
</children>
</Pane>
<JFXSlider fx:id="slider" layoutX="73.0" layoutY="534.0" prefHeight="24.0" prefWidth="192.0" style="-jfx-default-track: #659AB1; -jfx-default-thumb: #F2C75C" value="0.0" />
<Label fx:id="totalTime" alignment="CENTER" layoutX="266.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="Label" />
<Label fx:id="curnTime" alignment="CENTER" layoutX="11.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="Label" />
<Label fx:id="totalTime" alignment="CENTER" layoutX="266.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="00:00" />
<Label fx:id="curnTime" alignment="CENTER" layoutX="11.0" layoutY="537.0" prefHeight="18.0" prefWidth="61.0" text="00:00" />
</children></AnchorPane>
</children>
</AnchorPane>