vlcj Tutorial
Selected Reading
- vlcj - Discussion
- vlcj - Useful Resources
- vlcj - Quick Guide
- vlcj - Overlay
- vlcj - Audio Equalizer
- vlcj - Full Screen Video
- vlcj - Media Information
- vlcj - Logo
- vlcj - Marquee
- vlcj - Audio Player
- vlcj - Keyboard Events
- vlcj - Mouse Events
- vlcj - Error
- vlcj - Finished
- vlcj - Playing
- vlcj - Seek
- vlcj - Rewind
- vlcj - Pause
- vlcj - Play
- vlcj - Environment Setup
- vlcj - Overview
- vlcj - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
vlcj - Play
vlcj - Play Video
VLC Player Discovery
vlcj pbrary provides a class which does the auto discovery of installed VLC player in the system using following syntax.
EmbeddedMediaPlayerComponent mediaPlayerComponent = = new EmbeddedMediaPlayerComponent();
Load Video
Now using media we can easily load a video in our apppcation using following syntax−
mediaPlayerComponent.mediaPlayer().media().startPaused(path);
Play Video
Now using controls we can easily play a video in our apppcation using following syntax−
mediaPlayerComponent.mediaPlayer().controls().play();
Example
Open project mediaPlayer as created in
chapter in Ecppse.Update App.java with following code−
App.java
package com.tutorialspoint.media; 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.UIManager; import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent; pubpc class App extends JFrame { private static final long serialVersionUID = 1L; private static final String TITLE = "My First Media Player"; private static final String VIDEO_PATH = "D:\Downloads\sunset-beach.mp4"; private final EmbeddedMediaPlayerComponent mediaPlayerComponent; private JButton playButton; pubpc App(String title) { super(title); mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); } pubpc void initiapze() { this.setBounds(100, 100, 600, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { @Override pubpc void windowClosing(WindowEvent e) { mediaPlayerComponent.release(); System.exit(0); } }); JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); contentPane.add(mediaPlayerComponent, BorderLayout.CENTER); JPanel controlsPane = new JPanel(); playButton = new JButton("Play"); controlsPane.add(playButton); contentPane.add(controlsPane, BorderLayout.SOUTH); playButton.addActionListener(new ActionListener() { pubpc void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().play(); } }); this.setContentPane(contentPane); this.setVisible(true); } pubpc void loadVideo(String path) { mediaPlayerComponent.mediaPlayer().media().startPaused(path); } pubpc static void main( String[] args ){ try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.out.println(e); } App apppcation = new App(TITLE); apppcation.initiapze(); apppcation.setVisible(true); apppcation.loadVideo(VIDEO_PATH); } }
Run the apppcation by right cpcking the file and choose run as Java Apppcation. After a successful startup, if everything is fine then it should display the following result −
Cpck on Play Button and video will start playing.
Advertisements