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

AudioClip setCycleCount() set to greater than one or INDEFINITE plays the clip only once

XMLWordPrintable

    • x86
    • other

      FULL PRODUCT VERSION :
      java version "1.8.0_73"
      Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]

      A DESCRIPTION OF THE PROBLEM :
      When using an AudioClip in a JavaFX application, if you use setCycleCount() function it does not effect the playback when play() is called.

      Setting setCycleCount(4) then calling play() should make the AudioClip play 4 times, however it plays once only.

      Setting setCycleCount(INDEFINITE) then calling play() should cause the AudioClip to loop until stop() is called, however it also only plays once.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an AudioClip object with an audio file attached.

      Set cycle count > 1 using: audioClipObject.setCycleCount(4).

      Play clip on a button click or similar: audioClipObject.play()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Audio clip should loop 4 times.
      ACTUAL -
      Audio clip play through one time only.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package music;

      import java.nio.file.Paths;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.scene.media.AudioClip;
      import static javafx.scene.media.AudioClip.INDEFINITE;
      import javafx.stage.Stage;

      public class Music extends Application {
          
          static AudioClip currentMusic;

          @Override
          public void start(Stage primaryStage) {
              Button btn = new Button();
              btn.setText("Play");
              btn.setOnAction(e -> {
                  playMusic();
              });
              
              StackPane root = new StackPane();
              root.getChildren().add(btn);
              
              Scene scene = new Scene(root, 300, 250);
              
              primaryStage.setScene(scene);
              primaryStage.show();
          }
          
          public static void playMusic() {
              currentMusic = new AudioClip(Paths.get("src/SampleAudio.mp3").toUri().toString());
              currentMusic.setCycleCount(INDEFINITE);
              currentMusic.play();
          }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use method like answer in this StackOverflow question: http://stackoverflow.com/questions/23498376/ahow-to-make-a-mp3-repeat-in-javafx

            almatvee Alexander Matveev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: