Reputation: 217
I'm trying to use a JFileChooser
to load files to play in a MediaPlayer. I'm thinking I have to get the URI
as a string to achieve this, however, I get errors on illegal characters where there are spaces in the uri. I tried to prevent this by replacing spaces with %20
, but it doesn't seem to do anything.
Is there any way to get around this or should I use a completely different maneuver to load sound files?
My method looks as follows:
private void openFile()
{
int returnVal = fileChooser.showOpenDialog(frame);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
String uri = selectedFile.getPath();
String fileToAdd = uri.replace(" ", "%20");
tracklist.addTrack(fileToAdd);
}
}
Upvotes: 0
Views: 232
Reputation: 347314
You could simply use File#toURI
which will give you a URI
, which could then use toString
to generate a String
representation of the URI
which could then be added to the list...
Upvotes: 1