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

MediaPlayer does not release file handle for MP3 files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u45
    • javafx
      • 1.7.0_45 / JavaFX: 2.2.45-b18
      • Windows 7 64bit

      When loading MP3 files into MediaPlayer and subsequently trying to release the file in order to delete it, the file handle is kept open and the file cannot be deleted.

      When trying the same thing with .MP4 or .WAV files, it works as expected. Only the MP3 files cannot be deleted.

      Here is an example:

      import java.io.File;
      import java.nio.file.Files;
      import java.nio.file.StandardCopyOption;

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

      public class MediaPlayerTest extends Application {

      // Try this with .MP4 or .WAV and the file will be deleted
      // but not for .MP3
      File sourceFile = new File("d:\\mp3test\\test.mp3");
      File targetFile = new File("d:\\mp3test\\test_copy.mp3");

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

      @Override
      public void start(Stage stage) throws Exception {

      // Copy source file to target file
      Files.copy(sourceFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

      // Open media player
      Media media = new Media(targetFile.toURI().toString());
      MediaPlayer mp = new MediaPlayer(media);

      // Stop media player
      mp.stop();
      mp.dispose();
      mp = null;

      // Delete file copy
      System.out.println("Deleted?: " + targetFile.delete());

      }

      }

            Unassigned Unassigned
            dadapsjfx dadaps (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: