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

No seamless looping of audio files possible on Mac OSX

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 8u40
    • javafx
    • None

      Looping a sound with either javafx.scene.media.MediaPlayer or javafx.scene.media.AudioClip results in a clicking artefact making JFX audio unusable for things like background sounds in games or music.

      Two reproducible test cases attached. The file contains a test signal (perfect sine wave at 1 kHz) and loops perfectly.

      import javafx.application.Application;
      import javafx.scene.media.AudioClip;
      import javafx.stage.Stage;

      /**
       * Simple audio loop
       */
      public class AudioClipLoopTest extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              // download at https://www.dropbox.com/s/yagu1vsboqh0fv5/sinewave1s.wav
              final AudioClip clip = new AudioClip("file:" + System.getProperty("user.home") + "/tmp/sinewave1s.wav");
              clip.setCycleCount(AudioClip.INDEFINITE);
              clip.play();
          }

          public static void main(String[] args){
              launch(args);
          }
      }

      The same with MediaPlayer:

      import javafx.application.Application;
      import javafx.scene.media.AudioClip;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.stage.Stage;

      /**
       * Simple audio loop
       */
      public class MediaPlayerAudioLoopTest extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              // download at https://www.dropbox.com/s/yagu1vsboqh0fv5/sinewave1s.wav
              final Media media = new Media("file:" + System.getProperty("user.home") + "/tmp/sinewave1s.wav");
              final MediaPlayer player = new MediaPlayer(media);
              player.setCycleCount(AudioClip.INDEFINITE);
              player.setOnReady(()->player.play());
          }

          public static void main(String[] args){
              launch(args);
          }
      }

      In addition to that the MediaPlayer stops looping after 6 cycles, maybe related to RT-40409.

      I have not found a workaround, so if I do not use native frameworks directly or use a framework like libgdx, I cannot continue with my application.

            ddehaven David Dehaven (Inactive)
            rkruegerjfx Robert Krueger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: