some options for libvlc String[] libvlcArgs = {...add options here...}; // Create a factory MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs); // Create a full-screen strategy FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame); // Create a media player instance (in this example an embedded media player) EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer(fullScreenStrategy); // Set standard options as needed to be applied to all subsequently played media items String[] standardMediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.setStandardMediaOptions(standardMediaOptions); // Add a component to be notified of player events mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {...add implementation here...}); // Create and set a new component to display the rendered video (not shown: add the Canvas to a Frame) Canvas canvas = new Canvas(); CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas); mediaPlayer.setVideoSurface(videoSurface); // Play a particular item, with options if necessary String mediaPath = "/path/to/some/movie.mpg"; String[] mediaOptions = {...add options here...}; mediaPlayer.playMedia(mediaPath, mediaOptions); // Do some interesting things in the application ... // Cleanly dispose of the media player instance and any associated native resources mediaPlayer.release(); // Cleanly dispose of the media player factory and any associated native resources mediaPlayerFactory.release(); With regard to overlaying logos there are three approaches.
The first way is to specify standard options for the media player - this will set the logo for any subsequently played media item, for example:
String[] standardMediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.setStandardMediaOptions(standardMediaOptions);
The second way is to specify options when playing the media item, for example:
String[] mediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.playMedia(mediaPath, mediaOptions);
The final way is to use the methods of this class to set various logo properties, for example:
mediaPlayer.setLogoFile("vlcj-logo.png"); mediaPlayer.setLogoOpacity(25); mediaPlayer.setLogoLocation(10, 10); mediaPlayer.enableLogo(true);
For this latter method, it is not possible to enable the logo until after the video has started playing. There is also a noticeable stutter in video play-back when enabling the logo filter in this way.
With regard to overlaying marquees, again there are three approaches (similar to those for logos).
In this instance only the final way showing the usage of the API is used, for example:
mediaPlayer.setMarqueeText("VLCJ is quite good"); mediaPlayer.setMarqueeSize(60); mediaPlayer.setMarqueeOpacity(70); mediaPlayer.setMarqueeColour(Color.green); mediaPlayer.setMarqueeTimeout(3000); mediaPlayer.setMarqueeLocation(300, 400); mediaPlayer.enableMarquee(true);
With regard to video adjustment controls, after the video has started playing:
mediaPlayer.setAdjustVideo(true); mediaPlayer.setGamma(0.9f); mediaPlayer.setHue(10);
Some media when played may cause one or more media sub-items to created. These sub-items subsequently need to be played. The media player can be set to automatically play these sub-items via {@link #setPlaySubItems(boolean)}, otherwise {@link #playNextSubItem(String)} can beinvoked in response to a {@link MediaPlayerEventListener#finished(MediaPlayer)} event.
It is always a better strategy to reuse media player instances, rather than repeatedly creating and destroying instances.
Note that media player implementations will guarantee that native media player events are delivered in a single-threaded sequential manner.
@see EmbeddedMediaPlayerComponent