I want to get path of a music file and than add that file in my MP3-player using this code bellow:
addSong.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (fileChooser.showSaveDialog(MainFrame.this) == JFileChooser.APPROVE_OPTION) {
File song = fileChooser.getSelectedFile();
mainPanel.addSongs(song.getAbsolutePath()); // getting file path
JOptionPane.showMessageDialog(MainFrame.this,
"Song has been successfully added to your music track!", "Information",
JOptionPane.INFORMATION_MESSAGE);
}
}
});
Than I pass it like this:
public void addSongs(String path) {
musicPlayer.addSongs(path);
}
And in the end it comes here:
public void addSongs(String path) {
Media media = new Media(path); // this is place where error occurs
MediaPlayer mediaPlayer = new MediaPlayer(media);
songList.add(mediaPlayer);
}
And I got an error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Jovan\Desktop\DEAF KEV - Invincible [NCS Release].mp3
at javafx.scene.media.Media.<init>(Media.java:385)
at mp3.MusicPlayer.addSongs(MusicPlayer.java:86)
at mp3.MainPanel.addSongs(MainPanel.java:40)
at mp3.MainFrame$2.actionPerformed(MainFrame.java:78)
How to solve this problem ?