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

OnEndOfMedia not run for Media from within the jar

XMLWordPrintable

    • generic
    • generic

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]
      Microsoft Windows [Version 10.0.14393]

      A DESCRIPTION OF THE PROBLEM :
      When playing an audio file from within a jar using MediaPlayer the end of the audio does not trigger callbacks added to setOnEndOfMedia. The exact same code and audio file work when it is in the filesystem instead of packaged.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add "greeting.wav" PCM audio file to the /src folder.
      Use CladdLoader.getSystemResource to get a URL for the wav file
      Pass the url to a new Media
      Pass the new Media to a new MediaPlayer
      Call SetOnEndOfMedia and provide a callback that can be tested
      Call play() on the media player.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The audio from "greeting.wav" should be played and then the callback should be run.
      ACTUAL -
      When running from eclipse everything works as expected, file url is: file:/C:/Users/sbaker/workspace/AudioTest/bin/greeting.wav

      When running out of a jar, the audio plays, but the callback is never run. The url is: jar:file:/C:/gitprojects/erms/Application/Interface/DesktopAlerts/target/DesktopAlerts-jar-with-dependencies.jar!/chimes/greeting.wav

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package application;

      import java.net.URL;

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


      public class Main extends Application {
      @Override
      public void start(Stage primaryStage) {
      try {
      URL url = ClassLoader.getSystemResource("greeting.wav");
      System.out.println(url);
      Media media = new Media(url.toString());
      MediaPlayer mp = new MediaPlayer(media);
      mp.setOnEndOfMedia(() -> System.out.println("Reached End of Media!!!"));
      mp.play();
      } catch(Exception e) {
      e.printStackTrace();
      }
      }

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

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

      CUSTOMER SUBMITTED WORKAROUND :
      Store the file outside of the jar (e.g. on the local file system or on the web)

            scfitch Stephen Fitch
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: