I’m using JavaFX in an editor of an Eclipse RCP application to play video’s. During initialization of the editor UI, I do something along the lines:
canvas = new FXCanvas(imageSection, SWT.NONE);
canvas.setScene(createScene());
...
// createScene()
Media media = new Media(file.toURI().toString());
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);
...
player.play();
In the editor’s dispose method, I make sure the video stops playing:
@Override
public void dispose() {
player.stop();
super.dispose();
}
However, If I want to delete the video resource that was playing in the editor after the editor is closed (both from my own application or from windows explorer), the file cannot be deleted because it is still in use by my application. It appears fx’s Media object never released the video resource. I cannot find any pointer in the javafx documentation to ask the Media or MediaPlayer object to release the resource when the editor is closed.
My question: how can I make sure javafx releases the video file upon the editor closing?
For what it is worth, I posted my question on the JavaFX forum. In response, I was pointed to the this Jira ticket: http://javafx-jira.kenai.com/browse/RT-18224
The suggestion in the ticket didn’t help my situation, so I am stuck with my work-around.