-
Bug
-
Resolution: Unresolved
-
P4
-
7u45
-
- 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());
}
}
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());
}
}