Caprica Software

vlcj 3.x Tutorial

Marquee

Building on previous tutorials, we will now use the marquee to overlay some text 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 Marquee

You create a marquee by using a builder.

Marquee marquee = Marquee.marquee()
.text("vlcj tutorial")
.size(40)
.colour(Color.WHITE)
.timeout(3000)
.position(libvlc_marquee_position_e.bottom)
.opacity(0.8f)
.enable();

Using the Marquee

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

marquee.apply(mediaPlayerComponent.getMediaPlayer());

Alternatively:

mediaPlayerComponent.getMediaPlayer().setMarquee(marquee);

Marquee API

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

mediaPlayerComponent.getMediaPlayer().setMarqueeText("vlcj tutorial");
mediaPlayerComponent.getMediaPlayer().setMarqueeSize(40);
mediaPlayerComponent.getMediaPlayer().setMarqueeColour(Color.WHITE);
mediaPlayerComponent.getMediaPlayer().setMarqueeTimeout(3000);
mediaPlayerComponent.getMediaPlayer().setMarqueePosition(libvlc_marquee_position_e.bottom);
mediaPlayerComponent.getMediaPlayer().setMarqueeOpacity(0.8f);
mediaPlayerComponent.getMediaPlayer().enableMarquee(true);

Disabling the Marquee

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

Using the API directly:

mediaPlayerComponent.getMediaPlayer().enableMarquee(false);

Marquee Not Working?

The first thing to check is to make sure that you have enabled VLC's marquee 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 marquee module, make sure to use the following arguments (in addition to any others you need) with your MediaPlayerFactory:

String enableMarquee = "--sub-filter=marq"

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 marquee 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 marquee 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 marquee 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 marquee, you can try setting all of the necessary marquee options explicitly when you create a MediaPlayerFactory.