
- vlcj Tutorial
- vlcj - Home
- vlcj - Overview
- vlcj - Environment Setup
- Handling Operations
- vlcj - Play
- vlcj - Pause
- vlcj - Rewind
- vlcj - Seek
- Handling Events
- vlcj - Playing
- vlcj - Finished
- vlcj - Error
- vlcj - Mouse Events
- vlcj - Keyboard Events
- Utilities
- vlcj - Audio Player
- vlcj - Marquee
- vlcj - Logo
- vlcj - Media Information
- vlcj - Full Screen Video
- vlcj - Audio Equalizer
- vlcj - Overlay
- vlcj Useful Resources
- vlcj - Quick Guide
- vlcj - Useful Resources
- vlcj - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
vlcj - Pause Video
Let's enhance the application further in which we'll update vlcj Play Video chapter with pause video capability.
Pause Video
Now using controls we can easily pause a video in our application using following syntax−
mediaPlayerComponent.mediaPlayer().controls().pause();
Example
Open project mediaPlayer as created in Environment Setup chapter in Eclipse.
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; public 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; private JButton pauseButton; public App(String title) { super(title); mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); } public void initialize() { this.setBounds(100, 100, 600, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { @Override public 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); pauseButton = new JButton("Pause"); controlsPane.add(pauseButton); contentPane.add(controlsPane, BorderLayout.SOUTH); playButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().play(); } }); pauseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mediaPlayerComponent.mediaPlayer().controls().pause(); } }); this.setContentPane(contentPane); this.setVisible(true); } public void loadVideo(String path) { mediaPlayerComponent.mediaPlayer().media().startPaused(path); } public static void main( String[] args ){ try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.out.println(e); } App application = new App(TITLE); application.initialize(); application.setVisible(true); application.loadVideo(VIDEO_PATH); } }
Run the application by right clicking the file and choose run as Java Application. After a successful startup, if everything is fine then it should display the following result −

Click on Play Button and video will start playing then click on pause button. Now video will get paused.
Advertisements