Overlay for VLCJ Embeded Media Player

There are many methods to create a transparent overlay for a VLCJ Embedded Media Player. Few, however, allow dynamic updating of swing components.

To create an overlay for a VLCJ media player window that can display dynamically updated data through Swing components, such as JLabels, you will need to begin by creating a nested class that extends JWindow, as shown here:

The only things that are required here are the extension of the class JWindow, the constructor, the super call, the call of AWTUtilities to set the window opaque, and the call to set layout to null.

The next step can be done in the constructor of the player class which you have used to create your media player. First create three global variables:

Then, these lines must be added to the constructor:

Altogether, these lines will specify your nested overlay class as the overlay for the VLCJ media player you created with EmbeddedMediaPlayer. 

A few specifics: 
  • the instance of the overlay class you create must be passed the JFrame that contains the Canvas declared later (whether this is your Player class itself or an object created within it, as it is here); 
  • the Canvas created here is the holder for your media player and its overlay; 
  • the setOverlay method will cause your Overlay class to be painted over the media player at run-time. 
With this done, all one has to do to have a swing component painted over the player is add it to the Overlay class in its constructor with a call of the add() method. A good way to do this is to create the swing components as static objects in the Player class so that they can be accessed by and changed throughout the program.

No comments:

Post a Comment