working with vlcj and java: making a instance from class B (the EmbeddedMediaPlayerComponent class) in class A:
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
opens via class B: new JFrame
with a ebedded mediaPlayer
.
I can destroy this 'JFrame' with:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
stillAlive = false;
release(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public boolean stillAlive() {
return stillAlive;
}
but mediaPlayerComponent
in class A still exists and throws ugly errors if I try to reuse the mediaPlayerComponent
So if I want to play a new file, I do this.
check if its the first time opening an instance and
check if I did a release(true)
via the stillAlive = false
.
Otherwise reuse the mediaPlayerComponent.
if (mediaPlayerComponent == null || (! mediaPlayerComponent.stillAlive())) { // keine facory
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
mediaPlayerComponent.getMediaPlayer().prepareMedia(marked.getPath());
mediaPlayerComponent.getMediaPlayer().play();
} else {
mediaPlayerComponent.getMediaPlayer().prepareMedia(marked.getPath());
mediaPlayerComponent.getMediaPlayer().play();
}
Is there a nicer way? Like telling class A to set mediaPlayerComponent = null
.
It somehow seams to be bad coding stile to carry this boolean around.