// This latch is used simply to cleanly exit the application when the
// "finished" event is raised
final CountDownLatch latch = new CountDownLatch(1);
NativeLog log = mediaPlayerComponent.getMediaPlayerFactory().newLog();
if (log == null) {
System.out.println("Native log not available on this platform");
System.exit(1);
}
log.setLevel(libvlc_log_level_e.DEBUG);
log.addLogListener(new LogEventListener() {
@Override
public void log(libvlc_log_level_e level, String module, String file, Integer line, String name, String header, Integer id, String message) {
System.out.printf("[%-20s] (%-20s) %7s: %s\n", module, name, level, message);
}
});
mediaPlayerComponent.getMediaPlayer().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
@Override
public void finished(MediaPlayer mediaPlayer) {
latch.countDown();
}
@Override
public void error(MediaPlayer mediaPlayer) {
latch.countDown();
}
});
mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
// Wait for finished/error
latch.await();
// Must release the components to exit (otherwise threads are left running)
log.release();
mediaPlayerComponent.release(true);
}