2

I want to create a video player in which I have only one button. When I click that button the JFilechooser appears. So I want to play the selected video.

package minimal.video.player;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MinimalVideoPlayer extends JFrame implements ActionListener{
    public JPanel contentPane;
    public JButton open;
    public MinimalVideoPlayer(){
        super("Minimal Video Player");
        setLayout(null);
        setBounds(350, 150, 700, 400);
        setBackground(Color.WHITE);
        
        contentPane = new JPanel();
        contentPane.setLayout(null);
        contentPane.setBounds(350, 150, 700, 400);
        contentPane.setBackground(Color.WHITE);
        setContentPane(contentPane);
        
        ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("minimal/video/player/icon/open.png"));
        Image i2 = i1.getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH);
        ImageIcon i3 = new ImageIcon(i2);
        open = new JButton(i3);
        open.setBounds(300, 120, 100, 100);
        open.setBackground(Color.WHITE);
        open.setBorder(null);
        open.addActionListener(this);
        contentPane.add(open);
    }
    public static void main(String[] args) {
        new MinimalVideoPlayer().setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        JFileChooser chooser = new JFileChooser();
        int action = chooser.showOpenDialog(this);
        if (action != JFileChooser.APPROVE_OPTION) {
            return;
        }
        
//        What code do I need to insert here?
    }
}

I want to create a video player in which I have only one button. When I click that button the JFilechooser appears. So I want to play the selected video.

Prince
  • 21
  • 2
  • Hope this helps https://stackoverflow.com/questions/6525493/a-simple-way-of-embedding-a-video-in-my-swing-gui – geobreze Aug 02 '21 at 12:25
  • 1
    `What code do I need to insert here?` Java-FX code. There *are* Swing based 3rd party APIs to play video. JMF was a great API in its day, but has been long abandoned and does not support modern video format. There was also a 3rd party API based on VLC, but I've not heard anything of it for years now. If you go the Java-FX route, I'd recommend using *all* Java-FX components. @c0der there are actually *two* questions, one in the title and another hidden as a code comment in the source code. Both of them are too broad for an SO answer, but there are questions. – Andrew Thompson Aug 03 '21 at 12:02

0 Answers0