Caprica Software

vlcj 3.x Tutorial

Logo

Building on previous tutorials, we will now overlay a logo on the video.


Let's Get Started

You should now already have a basic template for how to create a vlcj application, so this tutorial will no longer duplicate all of the code each time - instead we'll just show the new code fragments.


Create a Logo

You create a logo by using a builder.

Logo logo = Logo.logo()
.file("vlcj-logo.png")
.position(libvlc_logo_position_e.top_left)
.opacity(0.3f)
.enable();

Using the Logo

For historical reasons there are two ways to use the logo, whichever way you choose is essentially a matter of preference.

logo.apply(mediaPlayerComponent.getMediaPlayer());

Alternatively:

mediaPlayerComponent.getMediaPlayer().setLogo(logo);

Logo API

You do not have to use the builder, you can invoke the individual API methods directly.

mediaPlayerComponent.getMediaPlayer().setLogoFile("vlcj-logo.png");
mediaPlayerComponent.getMediaPlayer().setLogoPosition(libvlc_logo_position_e.top_left);
mediaPlayerComponent.getMediaPlayer().setLogoOpacity(0.3f);
mediaPlayerComponent.getMediaPlayer().enableLogo(true);

Disabling the Logo

Using the builder approach, create a logo without invoking enable() and then apply or set it.

Using the API directly:

mediaPlayerComponent.getMediaPlayer().enableLogo(false);

Logo Not Working?

The first thing to check is to make sure that you have enabled VLC's logo sub-picture module. If you use the media player component framework (like EmbeddedMediaPlayerComponent rather than creating the media player yourself or via the factory, then this module is enabled by default.

If you do need to explicitly enable the logo module, make sure to use the following arguments (in addition to any others you need) with your MediaPlayerFactory:

String enableLogo = "--sub-filter=logo"

If you need to enable both marquee and logo together, as is often the case, you can specify arguments like this:

String enableLogoMarquee = "--sub-filter=logo:marq"

It is not possible to set and enable a logo dynamically on a media player until a short period of time after the media has started playing. It is not easy to know when this will work with 100% certainty.

The most obvious way to dynamically set the logo is on receipt of a videoOutput event in a MediaPlayerEventListener, but this might be a fraction too early. It will likely be prudent to kick off some sort of short timer in response to this event and set the logo when the timer expires.

There may be some other more reliable events such as those dealing with elementary streams, but frankly it is difficult to be certain about this.

If you do not need to dynamically set a logo, you can try setting all of the necessary logo options explicitly when you create a MediaPlayerFactory.