Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8118531

AudioClip: does not play sound when path/URL contains space character


    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.0
    • Component/s: javafx
    • Environment:

      Windows 7 64bit, Java 1.7.0 64bit, JavaFX b38 64bit


      When playing a file from the disk, AudioClip fails to play the sound when the path to the file contains a space character (the URL contains the %20 escaped sequence).
      There is no sound being played and no error is outputed.

      Sound files which do not contain spaces in their names are played Ok.

      I haven't tested if this happens the same when accessing an audio file within an archive or from the web.

       * To change this template, choose Tools | Templates
       * and open the template in the editor.
      package test;

      import java.io.File;
      import java.net.URL;
      import java.util.ArrayList;
      import java.util.List;
      import javafx.application.Application;
      import javafx.builders.FlowPaneBuilder;
      import javafx.collections.FXCollections;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.FlowPane;
      import javafx.scene.media.AudioClip;
      import javafx.stage.Stage;

       * @author fabriceb
      public class Main extends Application {

           * @param args the command line arguments
          public static void main(String[] args) {
              Application.launch(Main.class, args);

          public void start(Stage primaryStage) {
              String[] files = {
                  "C:\\Windows\\Media\\ding.wav", // Sound file from the disk.
                  "file:/c:/Windows/Media/chord.wav", // Sound file from the disk (URL-style).
                  "C:\\Windows\\Media\\Afternoon\\Windows Balloon.wav",
              List<Button> buttonList = new ArrayList<>(files.length);
              for (String file : files) {
                  final String f = file;
                  Button button = new Button(file);
                  button.setOnAction(new EventHandler<ActionEvent>() {

                      public void handle(ActionEvent event) {
              FlowPane buttonPane = FlowPaneBuilder.create().id("buttonPane").hgap(5).vgap(5).children(FXCollections.observableArrayList(buttonList)).build();
              Scene scene = new Scene(buttonPane);
              primaryStage.setTitle("AudioClip + resources access test");

          private void play(String resourcePath) {
              try {
                  URL url = null;
                  if (resourcePath.startsWith("http:") || resourcePath.startsWith("file:")) {
                      url = new URL(resourcePath);
                  } else {
                      ClassLoader loader = Main.class.getClassLoader();
                      url = loader.getResource(resourcePath);
                  if (url == null) {
                      File file = new File(resourcePath);
                      url = file.toURI().toURL();
                  AudioClip audioClip = new AudioClip(url.toExternalForm());
              } catch (Throwable t) {




            • Assignee:
              almatvee Alexander Matveev
              fbouyajfx Fabrice Bouyé (Inactive)
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: