Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:27+00:00 2026-06-17T04:49:27+00:00

1) Does JavaFX supports .wav format? (Not clear from Oracle’s page page) 2) If

  • 0

1) Does JavaFX supports .wav format?
(Not clear from Oracle’s page page)

2) If no, why so?

Swing is re-placement for AWT, and JavaFX for Swing, also
we say it’s easy to play .wav file format in Java, then why Media and MediaPlayer class of JavaFX doesn’t support .wav format? Any problems?

UPDATE

It gives me error when I try to play .wav files

UPDATE2 :

SSCCE:

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<Duration> 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<MediaPlayer> players = new ArrayList<MediaPlayer>();
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 < 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<ActionEvent>() {
  @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<ActionEvent>() {
  @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<MediaPlayer>() {
  @Override public void changed(ObservableValue<? extends MediaPlayer> 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<Duration>() {
  @Override public void changed(ObservableValue<? extends Duration> 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;
}
}

Exception:

     Exception in runnable
     MediaException: MEDIA_UNSUPPORTED : Compressed WAVE is not supported!
at javafx.scene.media.Media.<init>(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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:49:28+00:00Added an answer on June 17, 2026 at 4:49 am

    It seems clear enough to me – Supported Media Types

    ...
    MP4 MPEG-4 Part 14  H.264/AVC   AAC video/mp4, audio/x-m4a, video/x-m4v .mp4, .m4a, .m4v
    WAV Waveform Audio Format   N/A PCM audio/x-wav .wav
    

    EDIT :
    So the obvious answer (based on your edit) is that JavaFX doesn’t support compressed wave formats.

    WAV: Most WAV files are uncompressed, but they can hold compressed
    audio as well. JavaFX has no support for playing the compressed form
    yet. So when incorporating WAV files, developers need to make sure
    that the file format is WAV containing uncompressed PCM.

    source

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does JavaFX 2.0 supports printing? I have a text area from which I take
JavaFX 2 is not support Linux yet. Does this mean a client Linux machine
Does it make sense to start learning JavaFx if I do not have any
What exactly does a mobile need to be able to run JavaFX? Can it
How is the bind operator implemented in JavaFX? What happens behind the scenes? Does
C:\Tomcat5.5\webapps\WEB-INF\classes>javac MyServlet.java MyServlet.java:2: package javax.servlet does not exist import javax.servlet.*; ^ MyServlet.java:3: package javax.servlet.http
How does one easily apply custom (reusable) cellFactories to javafx.scene.control.TableCell; or javafx.scene.control.TableView; ?
Does a JavaFX applet use the browser's cache or any cache when downloading files
In my grails application, I needed to execute some javascript (not JSON) fetched from
JavaFX 2 seems to ship with a completely new media playback API not related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.