Created a video player based on the video tutorial . Code:

import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import javax.media.ControllerListener; import javax.media.Manager; import javax.media.*; public class VideoPlayer extends javax.swing.JFrame implements ActionListener, ControllerListener { File file; Player player; Component controlcom; Container con; public VideoPlayer() { initComponents(); } private void initComponents() { filechooser = new javax.swing.JFileChooser(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setPreferredSize(new java.awt.Dimension(800, 600)); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); jMenu1.setText("Файл"); jMenuItem1.setText("Відкрити"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuItem2.setText("Вихід"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuBar1.add(jMenu1); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 745, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 350, Short.MAX_VALUE) ); pack(); } private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) { new Start().setVisible(true); } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { try{getFile(); createFile();} catch(Exception e){} } private void formWindowOpened(java.awt.event.WindowEvent evt) { Dimension sSize = Toolkit.getDefaultToolkit ().getScreenSize (); setSize (sSize); setResizable(false); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new VideoPlayer().setVisible(true); } }); } private javax.swing.JFileChooser filechooser; private javax.swing.JMenu jMenu1; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; public void controllerUpdate(ControllerEvent ce) { try { con = getContentPane(); if (ce instanceof RealizeCompleteEvent) { Component visualcomponent = player.getVisualComponent(); if(visualcomponent!= null) { con.add(visualcomponent,BorderLayout.CENTER);} controlcom = player.getControlPanelComponent();} if(controlcom!=null){ con.add(controlcom,BorderLayout.SOUTH); } con.doLayout(); } catch(Exception e){} } private void getFile() throws FileNotFoundException { filechooser.showOpenDialog(this); file = filechooser.getSelectedFile(); if(file.exists()){ throw new FileNotFoundException();} } private void createFile() { try{player = Manager.createRealizedPlayer(file.toURL()); player.addControllerListener(this); player.realize();} catch(Exception e){} } @Override public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } 

In the end, the file does not open MPEG , as in the video, or in any other way.

Mistake

Unable to handle format: MPEG, 1280x720, FrameRate = 29.9, Length = 1382400

  • and writes any errors? Can you show a piece of stacktrace? - Evgeny Lebedev
  • There is nothing odd inside the program in the console. There is nothing strange only the execution time and everything .... I do not understand what the stacktrace is? - Oleg Grigorenko
  • fixed video starts sound goes but no pictures now - Oleg Grigorenko
  • show what writes in runtime exception - Evgeny Lebedev

0