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

Stopping an AudioClip, stops all AudioClips with the same source

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Pro 1809 (17763.253)
      openjdk full version "11.0.2+7"


      A DESCRIPTION OF THE PROBLEM :
      If I create multiple AudioClip instances with the same source String, then play them all concurrently, then stop 1 of the instances, they are all stopped.
      Note that the source Strings must be exactly the same: if different source Strings are used, but they point to the same file, then the behavior is as expected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      * create EntryPoint.java as given below
      * run it


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Stopping the AudioClips is independent of each other
      ACTUAL -
      All AudioClips are stopped on stopping the first

      ---------- BEGIN SOURCE ----------
      import java.net.URI;
      import java.time.Duration;
      import java.util.Arrays;
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.AnchorPane;
      import javafx.scene.media.AudioClip;
      import javafx.stage.Stage;

      import static java.util.stream.Collectors.toList;
      import static javafx.scene.paint.Color.WHITE;

      public class EntryPoint extends Application {

          @Override
          public void start(Stage stage) {
              stage.setTitle("AudioClip demo");
              stage.setScene(new Scene(new AnchorPane(), 640, 480, WHITE));
              stage.show();

              List<URI> sounds = Arrays.asList(
                      URI.create("https://sample-videos.com/audio/mp3/wave.mp3"),
                      URI.create("https://sample-videos.com/audio/mp3/wave.mp3"),
                      URI.create("https://sample-videos.com/audio/mp3/wave.mp3")
              );
              List<AudioClip> players = sounds.stream()
                      .map(sound -> new AudioClip(sound.toString()))
                      .collect(toList());

              for (AudioClip p : players) {
                  p.play();
                  System.out.println("started one");
                  sleep(Duration.ofSeconds(2));
              }
              sleep(Duration.ofSeconds(5));
              for (AudioClip p : players) {
                  p.stop();
                  System.out.println("stopped one");
                  sleep(Duration.ofSeconds(5));
              }
          }

          private void sleep(Duration duration) {
              try {
                  Thread.sleep(duration.toMillis());
              } catch (InterruptedException ignored) {
                  Thread.currentThread().interrupt();
              }
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can refer to the same source multiple times, but use different String representations, e.g.:
      https://sample-videos.com/audio/mp3/../../audio/mp3/wave.mp3
      https://sample-videos.com/audio/mp3/../mp3/wave.mp3
      When doing so, the result is as expected

        Attachments

          Activity

            People

            • Assignee:
              almatvee Alexander Matveev
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: