title: Why JavaFX dosn't support .wav format?
body: <p>1) Does JavaFX supports .wav format?
  (Not clear from <a href="http://docs.oracle.com/javafx/2/api/javafx/scene/media/package-summary.html" rel="nofollow">Oracle's page</a> page)</p>
  
  <p>2) If no, why so?</p>
  
  <p>Swing is re-placement for AWT, and JavaFX for Swing, also
  we say it's easy to play <code>.wav</code> file format in Java, then why  <code>Media</code> and <code>MediaPlayer</code> class of JavaFX doesn't support <code>.wav</code> format?  Any problems?</p>
  
  <h3>UPDATE</h3>
  
  <p>It gives me error when I try to play .wav files</p>
  
  <p><strong>UPDATE2 :</strong></p>
  
  <p>SSCCE:</p>
  
  <pre><code>import java.io.File;
  import java.io.FilenameFilter;
  import java.util.ArrayList;
  import java.util.List;
  import javafx.application.Platform;
  import javafx.beans.value.*;
  import javafx.embed.swing.JFXPanel;
  import javafx.event.*;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.control.*;
  import javafx.scene.layout.*;
  import javafx.scene.media.*;
  import javafx.util.Duration;
  import javax.swing.*;
  
   /** Example of playing all mp3 audio files in a given directory 
   * using a JavaFX MediaView launched from Swing 
   */
  public class NewFXMain {
  private static void initAndShowGUI() {
  // This method is invoked on Swing thread
  JFrame frame = new JFrame("FX");
  final JFXPanel fxPanel = new JFXPanel();
  frame.add(fxPanel);
  frame.setBounds(200, 100, 800, 250);
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.setVisible(true);
  
  Platform.runLater(new Runnable() {
    @Override public void run() {
      initFX(fxPanel);        
    }
   });
   }
  
   private static void initFX(JFXPanel fxPanel) {
  // This method is invoked on JavaFX thread
  Scene scene = new SceneGenerator().createScene();
  fxPanel.setScene(scene);
  }
  
  public static void main(String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
    @Override public void run() {
      initAndShowGUI();
    }
   });
   }
   }
  
   class SceneGenerator {    
   final Label currentlyPlaying = new Label();
   final ProgressBar progress = new ProgressBar();
   private ChangeListener&lt;Duration&gt; progressChangeListener;
  
   public Scene createScene() {
  final StackPane layout = new StackPane();
  
   // determine the source directory for the playlist
  final File dir = new File("e:\\");
  if (!dir.exists() || !dir.isDirectory()) {
    System.out.println("Cannot find video source directory: " + dir);
    Platform.exit();
    return null;
  }
  
  // create some media players.
  final List&lt;MediaPlayer&gt; players = new ArrayList&lt;MediaPlayer&gt;();
  for (String file : dir.list(new FilenameFilter() {
    @Override public boolean accept(File dir, String name) {
      return name.endsWith(".wav");
    }
  })) players.add(createPlayer("file:///" + (dir + "\\" + file).replace("\\", "/").replaceAll(" ", "%20")));
   if (players.isEmpty()) {
    System.out.println("No audio found in " + dir);
    Platform.exit();
    return null;
  }    
  
  // create a view to show the mediaplayers.
  final MediaView mediaView = new MediaView(players.get(0));
  final Button skip = new Button("Skip");
  final Button play = new Button("Pause");
  
  // play each audio file in turn.
  for (int i = 0; i &lt; players.size(); i++) {
    final MediaPlayer player     = players.get(i);
    final MediaPlayer nextPlayer = players.get((i + 1) % players.size());
    player.setOnEndOfMedia(new Runnable() {
      @Override public void run() {
        player.currentTimeProperty().removeListener(progressChangeListener);
        mediaView.setMediaPlayer(nextPlayer);
        nextPlayer.play();
      }
    });
    }
  
  // allow the user to skip a track.
  skip.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
    @Override public void handle(ActionEvent actionEvent) {
      final MediaPlayer curPlayer = mediaView.getMediaPlayer();
      MediaPlayer nextPlayer = players.get((players.indexOf(curPlayer) + 1) %       players.size());
      mediaView.setMediaPlayer(nextPlayer);
      curPlayer.currentTimeProperty().removeListener(progressChangeListener);
      curPlayer.stop();
      nextPlayer.play();
    }
     });
  
   // allow the user to play or pause a track.
   play.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
    @Override public void handle(ActionEvent actionEvent) {
      if ("Pause".equals(play.getText())) {
        mediaView.getMediaPlayer().pause();
        play.setText("Play");
      } else {
        mediaView.getMediaPlayer().play();
        play.setText("Pause");
      }
    }
   });
  
   // display the name of the currently playing track.
   mediaView.mediaPlayerProperty().addListener(new ChangeListener&lt;MediaPlayer&gt;() {
    @Override public void changed(ObservableValue&lt;? extends MediaPlayer&gt; observableValue, MediaPlayer oldPlayer, MediaPlayer newPlayer) {
      setCurrentlyPlaying(newPlayer);
    }
   });
  
   // start playing the first track.
   mediaView.setMediaPlayer(players.get(0));
   mediaView.getMediaPlayer().play();
   setCurrentlyPlaying(mediaView.getMediaPlayer());
  
  
   Button invisiblePause = new Button("Pause");
   invisiblePause.setVisible(false);
   play.prefHeightProperty().bind(invisiblePause.heightProperty());
   play.prefWidthProperty().bind(invisiblePause.widthProperty());
  
   // layout the scene.
   layout.setStyle("-fx-background-color: cornsilk; -fx-font-size: 20; -fx-padding: 20; -fx-alignment: center;");
   layout.getChildren().addAll(
    invisiblePause,
    VBoxBuilder.create().spacing(10).alignment(Pos.CENTER).children(
      currentlyPlaying,
      mediaView,
      HBoxBuilder.create().spacing(10).alignment(Pos.CENTER).children(skip, play, progress).build()
    ).build()
    );
   progress.setMaxWidth(Double.MAX_VALUE);
   HBox.setHgrow(progress, Priority.ALWAYS);
   return new Scene(layout, 800, 600);
   }
  
  
   private void setCurrentlyPlaying(final MediaPlayer newPlayer) {
   progress.setProgress(0);
   progressChangeListener = new ChangeListener&lt;Duration&gt;() {
    @Override public void changed(ObservableValue&lt;? extends Duration&gt; observableValue, Duration oldValue, Duration newValue) {
      progress.setProgress(1.0 * newPlayer.getCurrentTime().toMillis() / newPlayer.getTotalDuration().toMillis());
    }
    };
   newPlayer.currentTimeProperty().addListener(progressChangeListener);
  
   String source = newPlayer.getMedia().getSource();
   source = source.substring(0, source.length() - ".mp4".length());
   source = source.substring(source.lastIndexOf("/") + 1).replaceAll("%20", " ");
   currentlyPlaying.setText("Now Playing: " + source);
   }
  
    /** @return a MediaPlayer for the given source which will report any errors it    encounters */
   private MediaPlayer createPlayer(String aMediaSrc) {
   System.out.println("Creating player for: " + aMediaSrc);
   final MediaPlayer player = new MediaPlayer(new Media(aMediaSrc));
   player.setOnError(new Runnable() {
    @Override public void run() {
      System.out.println("Media error occurred: " + player.getError());
    }
   });
  return player;
  }
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>     Exception in runnable
       MediaException: MEDIA_UNSUPPORTED : Compressed WAVE is not supported!
  at javafx.scene.media.Media.&lt;init&gt;(Unknown Source)
  at SceneGenerator.createPlayer(NewFXMain.java:176)
  at SceneGenerator.createScene(NewFXMain.java:74)
  at NewFXMain.initFX(NewFXMain.java:39)
  at NewFXMain.access$000(NewFXMain.java:20)
  at NewFXMain$1.run(NewFXMain.java:32)
  at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
  at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:722)
  </code></pre>