### Initialize EmbeddedMediaPlayerComponent with Custom Factory (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Demonstrates initializing an EmbeddedMediaPlayerComponent with a custom MediaPlayerFactory that has been pre-configured with specific options. This allows for a fully customized media player setup. ```Java String[] options = {option1, option2, option3}; MediaPlayerFactory factory = new MediaPlayerFactory(options); EmbeddedMediaPlayerComponent mediaPlayer = new EmbeddedMediaPlayerComponent( factory, null, null, null, null ); ``` -------------------------------- ### Install Yeoman and vlcj Generator (npm) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/starter-projects Installs Yeoman globally and the generator-vlcj from the NPM public repository. Requires Node.js and npm to be installed. ```bash npm install -g yo npm install -g generator-vlcj ``` -------------------------------- ### Get Available VLC Options (Command Line) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Demonstrates how to retrieve a list of available VLC options and arguments from the command line. Running 'vlc -H' provides detailed information about modules, filters, and their configurable parameters. ```Shell vlc -H ``` -------------------------------- ### Java VLCJ 4 Audio Player Example Source: https://capricasoftware.co.uk/tutorials/vlcj/4/garbage-collection A Java example demonstrating how to create and manage an audio media player using VLCJ 4. This code ensures the media player instance is kept in memory to prevent garbage collection and handles playback events like completion and errors. ```java package tutorial; import uk.co.caprica.vlcj.player.component.AudioPlayerComponent; import uk.co.caprica.vlcj.player.MediaPlayer; import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter; public class GoodCode { private final AudioMediaPlayerComponent mediaPlayerComponent; public static void main(String[] args) { GoodCode goodCode = new GoodCode(args[0]); try { Thread.currentThread().join(); } catch(InterruptedException e) { } } public GoodCode(String mrl) { mediaPlayerComponent = new AudioMediaPlayerComponent(); mediaPlayerComponent.mediaPlayer().events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { @Override public void finished(MediaPlayer mediaPlayer) { exit(0); } @Override public void error(MediaPlayer mediaPlayer) { exit(1); } }); mediaPlayerComponent.mediaPlayer().media().play(mrl); } private void exit(int result) { mediaPlayerComponent.release(); System.exit(result); } } ``` -------------------------------- ### Get Available Equalizer Presets Source: https://capricasoftware.co.uk/tutorials/vlcj/4/audio-equalizer Retrieves a list of all available preset names that can be used to initialize an equalizer. These names correspond to predefined audio profiles like 'Flat', 'Classical', etc. ```java List presetNames = factory.equalizer().presets(); ``` -------------------------------- ### Get All Track Information in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Queries and retrieves information for all available audio, video, and text (subtitle) tracks within the media. This provides a comprehensive overview of the media's technical composition. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); List trackInfo = mediaPlayer.media().info().tracks(); ``` -------------------------------- ### Get Chapter Descriptions in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Fetches a list of chapter descriptions for the current title. Each chapter includes an offset and duration. This is particularly useful for navigating within a DVD or similar media structure. ```java List chapters = mediaPlayerComponent.mediaPlayer().chapters().descriptions(); ``` -------------------------------- ### Prepare Media for Parsing (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Prepares media for parsing without starting playback. This is the initial step before asynchronously parsing the media to extract metadata. It takes a media resource locator (mrl) as input. ```java mediaPlayerComponent.mediaPlayer().media().prepare(mrl); ``` -------------------------------- ### Get All Chapter Descriptions in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Retrieves descriptions for all chapters across all titles within the media. This is useful for complex media like DVDs that may contain multiple main features or bonus content, each with its own set of chapters. ```java List> allChapters = mediaPlayerComponent.mediaPlayer().chapters().allDescriptions(); ``` -------------------------------- ### Play Audio File Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-audio-player Initiates playback of an audio file specified by a media resource locator (MRL). This method is used to start playing the audio content through the media player. ```java mediaPlayerComponent.mediaPlayer().media().play(mrl); ``` -------------------------------- ### Navigate and Set Chapters in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Enables navigation and control over chapters, including getting the total chapter count, the current chapter, setting a specific chapter, and moving to the next or previous chapter. This allows for fine-grained control over media playback. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); int chapterCount = mediaPlayer.chapters().count(); int currentChapter = mediaPlayer.chapters().chapter(); mediaPlayer.chapters().setChapter(newChapter); mediaPlayer.chapters().next(); mediaPlayer.chapters().previous(); ``` -------------------------------- ### Initialize MediaPlayerFactory with vlcj 4.x Source: https://capricasoftware.co.uk/tutorials/vlcj/4/first-steps This code snippet demonstrates the basic initialization of a MediaPlayerFactory in vlcj 4.x. This factory is essential for creating media players and relies on vlcj's intrinsic native discovery to locate LibVLC libraries. No explicit configuration is needed if VLC is installed in a standard location. ```java import uk.co.caprica.vlcj.factory.MediaPlayerFactory; public class Tutorial { public static void main(String[] args) { MediaPlayerFactory factory = new MediaPlayerFactory(); } } ``` -------------------------------- ### Get Title Descriptions in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Retrieves a list of title descriptions for the current media. This is useful for media like DVDs where titles represent different sections or content. The result is a List of TitleDescription objects. ```java List titles = mediaPlayerComponent.mediaPlayer().titles().descriptions(); ``` -------------------------------- ### Enable Rotate Video Filter via Factory (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Example of enabling the VLC rotate video filter by setting factory arguments. The '--video-filter' and 'rotate' arguments are passed to the MediaPlayerFactory constructor. ```Java MediaPlayerFactory factory = new MediaPlayerFactory("--video-filter", "rotate"); EmbeddedMediaPlayer mediaPlayer = factory.newEmbeddedMediaPlayer(); ``` -------------------------------- ### Navigate and Set Titles in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Provides functionality to get the total number of titles, the current title number, and to set a new title. This is essential for applications that need to switch between different titled sections of a media file. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); int titleCount = mediaPlayer.titles().count(); int currentTitle = mediaPlayer.titles().title(); mediaPlayer.titles().setTitle(newTitle); ``` -------------------------------- ### Initialize EmbeddedMediaPlayerComponent with vlcj 4.x Source: https://capricasoftware.co.uk/tutorials/vlcj/4/first-steps This Java code illustrates how to initialize an EmbeddedMediaPlayerComponent, which is a convenient way to embed a media player within a GUI application using vlcj 4.x. The component automatically creates and manages a MediaPlayerFactory, simplifying the setup process. ```java import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent; public class Tutorial { public static void main(String[] args) { EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); } } ``` -------------------------------- ### Enable Native Dialogs with MediaPlayerFactory in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/dialogs This code snippet demonstrates how to enable native dialogs using the MediaPlayerFactory. It involves creating a factory, obtaining a Dialogs component, and then enabling it. This setup routes any native dialog requests through the created Dialogs component. ```java MediaPlayerFactory factory = new MediaPlayerFactory(); Dialogs dialogs = factory.dialogs().newDialogs(); factory.dialogs().enable(dialogs); ``` -------------------------------- ### Get Specific Track Lists in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Provides convenient methods to directly retrieve lists of audio, video, or text (subtitle) tracks without the need for type casting. This simplifies accessing information for a particular track type. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); List audioTrackInfo = mediaPlayer.media().info().audioTracks(); List videoTrackInfo = mediaPlayer.media().info().videoTracks(); List textTrackInfo = mediaPlayer.media().info().textTracks(); ``` -------------------------------- ### Add vlcj Maven Dependency Source: https://capricasoftware.co.uk/tutorials/vlcj/4/installation This snippet shows the Maven dependency required to include vlcj and its JNA dependencies in your project. Add this to the `dependencies` section of your `pom.xml` file. ```xml uk.co.caprica vlcj 4.11.0 ``` -------------------------------- ### Create MediaPlayerFactory with List of Strings (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Shows how to initialize a MediaPlayerFactory using a List of Strings as configuration options. This provides another way to manage and pass VLC module and filter settings. ```Java List options = Arrays.asList(option1, option2, option3); MediaPlayerFactory factory = new MediaPlayerFactory(options); ``` -------------------------------- ### Play Media with Media Options Array (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Shows how to play media using the mediaPlayer.media().play() method, providing an array of String options. These options are applied during playback and can configure specific media behaviors. ```Java String[] options = {option1, option2, option3}; mediaPlayer.media().play(mrl, options); ``` -------------------------------- ### Get MediaPlayerFactory from EmbeddedMediaPlayerComponent Source: https://capricasoftware.co.uk/tutorials/vlcj/4/audio-equalizer Retrieves the MediaPlayerFactory instance from an EmbeddedMediaPlayerComponent, which is necessary for creating equalizer instances. This assumes you have already initialized an EmbeddedMediaPlayerComponent. ```java MediaPlayerFactory factory = mediaPlayerComponent.mediaPlayerFactory(); ``` -------------------------------- ### Play Media with Simple Option Syntax (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Presents a simple syntax for media options without any prefix, where the option name and value are separated by an equals sign. This syntax can also be effective for controlling playback. ```Java mediaPlayer.media().play(mrl, "start-time=30.5", "run-time=10"); ``` -------------------------------- ### Play Media with Combined Option Syntax (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Illustrates an alternate syntax for specifying media options, where the option name and value are combined with an equals sign. This is equivalent to passing them as separate arguments. ```Java mediaPlayer.media().play(mrl, "--rotate-angle=30"); ``` -------------------------------- ### Create MediaPlayerFactory with Variable Arguments (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Illustrates creating a MediaPlayerFactory with variable arguments, allowing a flexible number of String options to be passed directly. This is an alternative to using a String array for configuration. ```Java MediaPlayerFactory factory = new MediaPlayerFactory(option1, option2, option3); ``` -------------------------------- ### Custom Painting on Overlay in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/overlay Overrides the `paint` method to add custom Java2D drawing to the overlay. This example demonstrates alpha-blended gradient painting and drawing ovals, showing that transparency and custom rendering work correctly. ```java @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint( 180.0f, 280.0f, new Color(255, 255, 255, 255), 250.0f, 380.0f, new Color(255, 255, 0, 0) ); g2.setPaint(gp); for (int i = 0; i < 3; i ++ ) { g2.drawOval(150, 280, 100, 100); g2.fillOval(150, 280, 100, 100); g2.translate(120, 20); } } ``` -------------------------------- ### Create MediaPlayerFactory with String Array Options (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Demonstrates creating a MediaPlayerFactory instance by passing an array of String options. These options are used to configure VLC modules and filters when initializing the media player. ```Java String[] options = {option1, option2, option3}; MediaPlayerFactory factory = new MediaPlayerFactory(options); ``` -------------------------------- ### Get Frequency Band Values Source: https://capricasoftware.co.uk/tutorials/vlcj/4/audio-equalizer Retrieves a list of frequency values (in Hz) for each band supported by the equalizer. This information is useful for labeling user interface controls like sliders. ```java List bands = factory.equalizer().bands(); ``` -------------------------------- ### Specify Keystore for MediaPlayerFactory in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/dialogs This code shows how to create a MediaPlayerFactory instance with a specified keystore. This is crucial for handling login dialogs correctly, as omitting the keystore can cause the application to hang when a login dialog is requested. ```java MediaPlayerFactory factory = new MediaPlayerFactory("--keystore=secret"); ``` -------------------------------- ### Create Basic Swing Application with JFrame Source: https://capricasoftware.co.uk/tutorials/vlcj/4/my-first-media-player Initializes a standard Java Swing application with a JFrame. This sets up the basic window structure for the media player. No external dependencies beyond standard Java libraries are required at this stage. ```java import javax.swing.JFrame; import javax.swing.SwingUtilities; public class Tutorial { private final Tutorial thisApp; private final JFrame frame; public static void main(String[] args) { thisApp = new Tutorial(); } public Tutorial() { frame = new JFrame("My First Media Player"); frame.setBounds(100, 100, 600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Get Specific Track Types in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Fetches track information for specified types, such as audio and video. This allows developers to focus on particular track details without processing unnecessary data. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); List trackInfo = mediaPlayer.media().info().tracks(TrackType.AUDIO, TrackType.VIDEO); ``` -------------------------------- ### Instantiate Overlay with Owner Frame in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/overlay Shows how to instantiate the custom `Overlay` class, passing the main application frame as the owner. This is crucial for proper window management and lifecycle. ```java Overlay overlay = new Overlay(mainFrame); ``` -------------------------------- ### Play Media with Colon-Prefixed Options (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/options-arguments Shows a syntax for media options that uses a colon prefix for each option. This is particularly useful for options like 'start-time' and 'run-time' to control playback duration and position. ```Java mediaPlayer.media().play(mrl, ":start-time=30.5", ":run-time=10"); ``` -------------------------------- ### Create Transparent Overlay Window in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/overlay Demonstrates the minimal code required to create a transparent overlay window. It extends the `Window` class and sets a fully transparent background. Note: Prior to Java 7, `AWTUtilities.setWindowOpaque(this, false)` might be needed. ```java public class Overlay extends Window { public Overlay(Window owner) { super(owner, WindowUtils.getAlphaCompatibleGraphicsConfiguration()); setBackground(new Color(0, 0, 0, 0)); } } ``` -------------------------------- ### Set up UI Layout with Media Player and Controls (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-controls Configures the application's main frame to include a media player component and a separate panel for playback control buttons. It uses Swing's BorderLayout to arrange these components. ```Java JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); contentPane.add(mediaPlayerComponent, BorderLayout.CENTER); JPanel controlsPane = new JPanel(); pauseButton = new JButton("Pause"); controlsPane.add(pauseButton); rewindButton = new JButton("Rewind"); controlsPane.add(rewindButton); skipButton = new JButton("Skip"); controlsPane.add(skipButton); contentPane.add(controlsPane, BorderLayout.SOUTH); frame.setContentPane(contentPane); frame.setVisible(true); ``` -------------------------------- ### Create Direct Rendering Media Player with CallbackMediaPlayerComponent (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/direct-rendering This Java code demonstrates the creation of a media player using vlcj's CallbackMediaPlayerComponent for direct rendering. It sets up a JFrame, initializes the component, and plays a media file specified in the command-line arguments. The primary change from embedded players is the use of CallbackMediaPlayerComponent. ```java package tutorial; import javax.swing.JFrame; import javax.swing.SwingUtilities; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import uk.co.caprica.vlcj.component.CallbackMediaPlayerComponent; public class Tutorial { private final Tutorial thisApp; private final JFrame frame; private final CallbackMediaPlayerComponent mediaPlayerComponent; public static void main(String[] args) { Tutorial thisApp = new Tutorial(); } public Tutorial() { frame = new JFrame("My First Media Player"); frame.setBounds(100, 100, 600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { mediaPlayerComponent.release(); System.exit(0); } }); mediaPlayerComponent = new CallbackMediaPlayerComponent(); // This is the only change frame.setContentPane(mediaPlayerComponent); frame.setVisible(true); mediaPlayerComponent.mediaPlayer().media().play(args[0]); } } ``` -------------------------------- ### Create New vlcj Project with Yeoman (bash) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/starter-projects Demonstrates the steps to create a new vlcj project directory and invoke the Yeoman generator. This initiates an interactive process to configure the project. ```bash mkdir my-cool-project cd my-cool-project yo vlcj ``` -------------------------------- ### Add Media Player Event Listeners Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-audio-player Attaches event listeners to the media player to handle playback events such as 'finished' and 'error'. The listeners are implemented using MediaPlayerEventAdapter, and in this example, they trigger application exit. ```java mediaPlayerComponent.mediaPlayer().events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { @Override public void finished(MediaPlayer mediaPlayer) { exit(0); } @Override public void error(MediaPlayer mediaPlayer) { exit(1); } }); ``` -------------------------------- ### Complete Audio Player Application Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-audio-player The complete Java code for a command-line audio player using vlcj 4.x. It initializes the player, sets up event handlers, plays an audio file passed as a command-line argument, and manages application lifecycle. ```java package tutorial; import uk.co.caprica.vlcj.player.component.AudioPlayerComponent; import uk.co.caprica.vlcj.player.base.MediaPlayer; import uk.co.caprica.vlcj.player.base.MediaPlayerEventAdapter; public class Tutorial { private final AudioPlayerComponent mediaPlayerComponent; public static void main(String[] args) { Tutorial tutorial = new Tutorial(); tutorial.start(args[0]); try { Thread.currentThread().join(); } catch(InterruptedException e) { } } private Tutorial() { mediaPlayerComponent = new AudioPlayerComponent(); mediaPlayerComponent.mediaPlayer().events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() { @Override public void finished(MediaPlayer mediaPlayer) { exit(0); } @Override public void error(MediaPlayer mediaPlayer) { exit(1); } }); } private void start(String mrl) { mediaPlayerComponent.mediaPlayer().media().play(mrl); } private void exit(int result) { // It is not allowed to call back into LibVLC from an event handling thread, so submit() is used mediaPlayerComponent.mediaPlayer().submit(new Runnable() { @Override public void run() { mediaPlayerComponent.mediaPlayer().release(); System.exit(result); } }); } } ``` -------------------------------- ### Configure Full Screen Strategy with EmbeddedMediaPlayer (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/full-screen This code snippet demonstrates how to set the `AdaptiveFullScreenStrategy` directly on an `EmbeddedMediaPlayer` instance. This approach is used when not utilizing the `EmbeddedMediaPlayerComponent`. It also requires a reference to the application's main window or frame. ```java mediaPlayer.fullScreen().strategy(new AdaptiveFullScreenStrategy(window)); ``` -------------------------------- ### Configure Full Screen Strategy with EmbeddedMediaPlayerComponent (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/full-screen This code snippet shows how to configure the `AdaptiveFullScreenStrategy` when using the `EmbeddedMediaPlayerComponent`. This strategy automatically selects the appropriate full-screen implementation based on the operating system. It requires an instance of the application's main window or frame. ```java mediaPlayerComponent = new EmbeddedMediaPlayerComponent( null, null, new AdaptiveFullScreenStrategy(window), null, null ); ``` -------------------------------- ### Build vlcj Project with Maven (bash) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/starter-projects Builds the generated vlcj starter project using Maven. The command compiles the code, packages it, and prepares it for deployment or execution. ```bash mvn package ``` -------------------------------- ### Add Error Dialog Handler in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/dialogs This example shows how to add a handler for error dialog requests. The DialogHandler interface is implemented, and its displayError method is overridden to print the error details to the console. This allows custom handling of errors reported by VLC. ```java dialogs.addDialogHandler(new DialogHandler() { @Override public void displayError(Long userData, String title, String text) { System.out.printf("display error: %s - %s - %s%n", userData, title, text); } }); ``` -------------------------------- ### Create an Equalizer from a Preset Source: https://capricasoftware.co.uk/tutorials/vlcj/4/audio-equalizer Creates a new equalizer instance initialized with values from a predefined preset. The preset name must be one recognized by LibVLC. ```java Equalizer equalizer = factory.equalizer().newEqualizer(presetName); ``` -------------------------------- ### Create Audio Player Component Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-audio-player Instantiates an AudioPlayerComponent, which is a simplified media player for audio-only playback. It does not require a video surface, making it easier to use for audio applications. ```java mediaPlayerComponent = new AudioPlayerComponent(); ``` -------------------------------- ### Create VLCJ Media Player with UI Controls (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-controls This Java code demonstrates the creation of a simple media player application using the VLCJ 4 library. It sets up a JFrame with a video display area and control buttons (Pause, Rewind, Skip). The code initializes the EmbeddedMediaPlayerComponent, adds action listeners to the buttons to control media playback, and handles window closing events to release resources. ```java package tutorial; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent; public class Tutorial { private final Tutorial thisApp; private final JFrame frame; private final EmbeddedMediaPlayerComponent mediaPlayerComponent; private final JButton pauseButton; private final JButton rewindButton; private final JButton skipButton; public static void main(String[] args) { thisApp = new Tutorial(); } public Tutorial() { frame = new JFrame("My First Media Player"); frame.setBounds(100, 100, 600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { mediaPlayerComponent.release(); System.exit(0); } }); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); contentPane.add(mediaPlayerComponent, BorderLayout.CENTER); JPanel controlsPane = new JPanel(); pauseButton = new JButton("Pause"); controlsPane.add(pauseButton); rewindButton = new JButton("Rewind"); controlsPane.add(rewindButton); skipButton = new JButton("Skip"); controlsPane.add(skipButton); contentPane.add(controlsPane, BorderLayout.SOUTH); pauseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().pause(); } }); rewindButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().skip(-10000); } }); skipButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().skip(10000); } }); frame.setContentPane(contentPane); mediaPlayerComponent.getMediaPlayer().media().play(args[0]); } } ``` -------------------------------- ### Manage Media Tracks (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Provides functionality to get the total count of tracks, the currently active track, and to set a new active track for video, audio, and subpicture streams. A special track ID of -1 is often used to disable a stream. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); int videoTrackCount = mediaPlayer.video().trackCount(); int videoTrack = mediaPlayer.video().track(); mediaPlayer.video().setTrack(newVideoTrack); int audioTrackCount = mediaPlayer.audio().trackCount(); int audioTrack = mediaPlayer.audio().track(); mediaPlayer.audio().setTrack(newAudioTrack); int spuTrackCount = mediaPlayer.subpictures().trackCount(); int spuTrack = mediaPlayer.subpictures().track(); mediaPlayer.subpictures().setTrack(newSpuTrack); ``` -------------------------------- ### Get Track Descriptions (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/media-info Retrieves lists of available track descriptions for video, audio, and subpicture streams. These descriptions are typically used as labels in user interfaces to allow track selection. Each `TrackDescription` object contains a unique ID and a textual description. ```java MediaPlayer mediaPlayer = mediaPlayerComponent.mediaPlayer(); List videoTracks = mediaPlayer.video().trackDescriptions(); List audioTracks = mediaPlayer.audio().trackDescriptions(); List spuTracks = mediaPlayer.subpictures().trackDescriptions(); ``` -------------------------------- ### Implement VLCJ Error Event Handler in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/basic-events Handles the 'error' event, which signals a failure during media playback. This example displays a standard error dialog using JOptionPane, ensuring the UI update is executed on the Event Dispatch Thread via SwingUtilities.invokeLater. ```java @Override public void error(MediaPlayer mediaPlayer) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog( frame, "Failed to play media", "Error", JOptionPane.ERROR_MESSAGE ); } }); } ``` -------------------------------- ### Create a Blank Equalizer Instance Source: https://capricasoftware.co.uk/tutorials/vlcj/4/audio-equalizer Creates a new equalizer instance with all amplification values initially set to zero. This is useful when you want to define custom amplification levels from scratch. ```java Equalizer equalizer = factory.equalizer().newEqualizer(); ``` -------------------------------- ### Play Seekable Media with Options (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/java-io Demonstrates playing seekable media with additional media options passed during the `RandomAccessFileMedia` instantiation. These options can customize playback behavior. ```Java String[] mediaOptions = {...}; CallbackMedia media = new RandomAccessFileMedia(new File("MyCoolMovie.mp4"), mediaOptions); mediaPlayerComponent.mediaPlayer().media().play(media); ``` -------------------------------- ### Configure Marquee using Direct API (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/marquee This code illustrates how to configure marquee properties by directly invoking individual API methods on the MediaPlayer's marquee instance. This approach bypasses the builder pattern for granular control. ```java mediaPlayerComponent.mediaPlayer().marquee().setText("vlcj tutorial"); mediaPlayerComponent.mediaPlayer().marquee().setSize(40); mediaPlayerComponent.mediaPlayer().marquee().setColour(Color.WHITE); mediaPlayerComponent.mMediaPlayer().marquee().setTimeout(3000); mediaPlayerComponent.mMediaPlayer().marquee().setPosition(libvlc_marquee_position_e.bottom); mediaPlayerComponent.mediaPlayer().marquee().setOpacity(0.8f); mediaPlayerComponent.mediaPlayer().marquee().enable(true); ``` -------------------------------- ### Associate Overlay with MediaPlayer in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/overlay Associates the created overlay instance with the VLCJ media player. This step is necessary before the overlay can be displayed or controlled. ```java mediaPlayerComponent.mediaPlayer().overlay().set(overlay); ``` -------------------------------- ### Implement Adaptive Full-Screen Strategy with UI Component Hiding Source: https://capricasoftware.co.uk/tutorials/vlcj/4/full-screen This Java code snippet demonstrates how to implement a custom full-screen strategy using vlcj's `AdaptiveFullScreenStrategy`. It overrides `beforeEnterFullScreen` to hide UI components like `controlsPane` and `statusBar`, and `afterExitFullScreen` to restore their visibility. This is useful for ensuring only the video content is displayed in full-screen mode. ```java mediaPlayerComponent.mediaPlayer().fullScreen().strategy( new AdaptiveFullScreenStrategy(frame) { @Override protected void beforeEnterFullScreen() { controlsPane.setVisible(false); statusBar.setVisible(false); } @Override protected void afterExitFullScreen() { controlsPane.setVisible(true); statusBar.setVisible(true); } } ); ``` -------------------------------- ### Create Logo with Builder (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/logo This code snippet shows how to create a logo object using the vlcj Logo builder. It specifies the logo file, its position on the video, and its opacity. The `enable()` method is called to activate the logo. ```java Logo logo = Logo.logo() .file("vlcj-logo.png") .position(LogoPosition.TOP_LEFT) .opacity(0.3f) .enable(); ``` -------------------------------- ### Add Listeners to Video Surface for Mouse and Keyboard Events (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/mouse-keyboard This Java code demonstrates an alternative to template methods, where listeners are explicitly added to the video surface component for handling mouse and keyboard events. It includes MouseListener, MouseWheelListener, and KeyListener. ```java Component videoSurface = mediaPlayerComponent.videoSurfaceComponent(); videoSurface.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { } }); videoSurface.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { } }); videoSurface.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { } }); ``` -------------------------------- ### Apply Marquee to MediaPlayer (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/marquee Demonstrates two methods for applying a configured marquee to a vlcj MediaPlayer instance. The first uses the `apply` method, while the second uses the `set` method on the mediaPlayer's marquee instance. ```java marquee.apply(mediaPlayerComponent.mediaPlayer()); ``` ```java mediaPlayerComponent.mediaPlayer().marquee().set(marquee); ``` -------------------------------- ### Play Media File using EmbeddedMediaPlayerComponent Source: https://capricasoftware.co.uk/tutorials/vlcj/4/my-first-media-player Enables media playback by passing a file path to the EmbeddedMediaPlayerComponent. The media file path is expected as the first command-line argument. This builds upon the previous snippet by adding a single line to initiate playback. ```java import javax.swing.JFrame; import javax.swing.SwingUtilities; import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent; public class Tutorial { private final Tutorial thisApp; private final JFrame frame; private final EmbeddedMediaPlayerComponent mediaPlayerComponent; public static void main(String[] args) { thisApp = new Tutorial(args); } public Tutorial(String[] args) { frame = new JFrame("My First Media Player"); frame.setBounds(100, 100, 600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); frame.setContentPane(mediaPlayerComponent); frame.setVisible(true); mediaPlayerComponent.mediaPlayer().media().play(args[0]); } } ``` -------------------------------- ### Configure Logo via API (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/logo This code shows how to configure individual logo properties directly through the MediaPlayer's logo API. It allows setting the logo file, position, opacity, and enabling/disabling the logo without using the builder. ```java mediaPlayerComponent.mediaPlayer().logo().setFile("vlcj-logo.png"); mediaPlayerComponent.mediaPlayer().logo().setPosition(LogoPosition.TOP_LEFT); mediaPlayerComponent.mediaPlayer().logo().setOpacity(0.3f); mediaPlayerComponent.mediaPlayer().logo().enable(true); ``` -------------------------------- ### Set Full Screen Mode (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/full-screen This code snippet shows how to explicitly set the media player to full-screen mode. By calling `set(true)`, the player will enter full-screen. Conversely, `set(false)` would exit full-screen mode. This provides direct control over the player's display state. ```java mediaPlayerComponent.mediaPlayer().fullScreen().set(true); ``` -------------------------------- ### Request Focus for Video Surface Component (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/mouse-keyboard This Java code provides methods to programmatically request input focus for the video surface component, which is necessary for key events to be delivered. It shows two approaches: requestFocus() and requestFocusInWindow(). ```java mediaPlayerComponent.videoSurfaceComponent().requestFocus(); ``` ```java mediaPlayerComponent.videoSurfaceComponent().requestFocusInWindow(); ``` -------------------------------- ### Create Marquee using Builder (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/marquee This code snippet shows how to create a marquee object using the builder pattern in Java. It allows for fluent configuration of text, size, color, timeout, position, and opacity before enabling the marquee. ```java Marquee marquee = Marquee.marquee() .text("vlcj tutorial") .size(40) .colour(Color.WHITE) .timeout(3000) .position(MarqueePosition.BOTTOM_RIGHT) .opacity(0.8f) .enable(); ``` -------------------------------- ### Add Login Dialog Handler and Post Credentials in Java Source: https://capricasoftware.co.uk/tutorials/vlcj/4/dialogs This snippet illustrates adding a handler for login credential dialogs. It overrides the displayLogin method to process login requests, post credentials, or dismiss the dialog if login attempts fail. For this to work correctly, a keystore must be specified during MediaPlayerFactory creation. ```java dialogs.addDialogHandler(new DialogHandler() { private int loginCount = 0; @Override public void displayLogin(Long userData, DialogId id, String title, String text, String defaultUsername, boolean askStore) { System.out.printf("display login: %s - %s - %s - %s - %s - %s%n", userData, id, title, text, defaultUsername, askStore); // In a real application these would be requested in an actual dialog box, // or read from some configuration somewhere String username = "deckard"; String password = "nexus6"; if (loginCount < 3) { loginCount++; factory.dialogs().postLogin(id, username, password, false); } else { factory.dialogs().dismiss(id); } } }); ``` -------------------------------- ### Apply Logo to MediaPlayer (Java) Source: https://capricasoftware.co.uk/tutorials/vlcj/4/logo Demonstrates two ways to apply a pre-configured logo to a vlcj MediaPlayer instance. The first method uses the `apply` method of the logo object, while the second uses the `set` method directly on the mediaPlayer's logo configuration. ```java logo.apply(mediaPlayerComponent.mediaPlayer()); ``` ```java mediaPlayerComponent.mediaPlayer().logo().set(logo); ```