I’m building a small application, that can play video, the problem, that when I add a video with a whitespace in it’s path – it gives me an error:
java.net.URISyntaxException: Illegal character in opaque part at index 13: FILE:C:/Video menu/video/03.mp4
Here’s my scene:
Group root = new Group();
Scene scene = new Scene(root, 1280, 1024, Color.BLACK);
String path = new String("FILE:C:/Video menu/touchMV/03.mp4");
URI uri = new URI(path);
root.getChildren().add(
MediaViewBuilder.create()
.mediaPlayer(
MediaPlayerBuilder.create()
.media(
new Media(
path
)
).build()
).build()
);
stage.setScene(scene);
stage.show();
The Media(java.lang.String source) docs said that it have Constraints:
- The supplied URI must conform to RFC-2396 as required by java.net.URI.
- Only HTTP, FILE, and JAR URIs are supported.
I tried to pass a Media() constructor an (new URI(path)).toString(); and (new URI(path)).toASCIIString() it didn’t worked. Changing a whitespace to %20 didn’t worked as well.
What can I do in this situation?
I don’t know the cause of your problem, but it works if you create a
Filefirst and callFile#toURI#toASCIIString.