Я пытаюсь встроить видеоплеер в JFrame, как следует, когда пользователь нажимает на JMenu, а затем нажимает JMenuItem (открытое видео), когда JFileChooser появляется и запрашивает выберите видео и удалите JTextFile с правой стороны и установите видео в левую сторону, я сделал все это, но я не знаю, как поместить видео в Canvas, потому что он всегда дает ошибку, поэтому мне нужен способ записи, потому что я удалил вся строка ошибки, поэтому код здесь не дает никакой ошибки. У меня есть класс 2 класса для gui, а второй - тот, который я пишу здесь. Кто-нибудь может мне помочь, о чем писать в actionlistener и моем прикрепленном классекак воспроизвести видео, используя Canvas, который выбрал форму JFileChooser
это видео Вид деятельности
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package animeaid;
import java.awt.Canvas;
import java.awt.Color;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
/**
*
* @author isslam
*/
public class VideoOpration {
public static Canvas c;
VideoOpration() {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
c = new Canvas();
c.setBackground(Color.black);
EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(c));
mediaPlayer.playMedia(GuiInterface.mediaPath);
}
}
класс графического интерфейса, что объявить JFileChoosear
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package AnimeAid;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.table.*;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
/**
*
* @author isslam
*/
public class GuiInterface extends JFrame {
private final JTable table;
private final JTextField enterText;
private final JMenu jMenu1,jMenu2,jMenu3;
private final JMenuBar jMenuBar1;
private final JMenuItem itemNewSrt,itemOpenVideo;
private static JFileChooser ourFileSelector;
File ourFile;
public static String mediaPath="";
String vlcPath="C:\\Program Files\\VideoLAN\\VLC";
public GuiInterface(String title){
setSize(1024, 720);
setTitle(title);
setDefaultCloseOperation(GuiInterface.EXIT_ON_CLOSE);
String[] columnNames = {"#","Start","End","Translation column"};
Object[][] data = {
{"1", "00:00:01,600","00:00:04,080", "Mr Magnussen, please state your\n" +
"full name for the record."},
{"2", "00:00:04,080 ","00:00:07,040","Charles Augustus Magnussen."}};
enterText = new JTextField();
ourFileSelector = new JFileChooser();
jMenuBar1 = new JMenuBar();
jMenu1 = new JMenu("File");
jMenu2 = new JMenu("Video");
jMenu3 = new JMenu("Subtitle");
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenu3);
itemNewSrt = new JMenuItem("this text only");
jMenu1.add(itemNewSrt);
itemOpenVideo = new JMenuItem("Open Video");
jMenu2.add(itemOpenVideo);
setJMenuBar(jMenuBar1);
table = new JTable(data, columnNames);
table.setFillsViewportHeight(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
TableColumn columnA = table.getColumn("#");
columnA.setMinWidth(10);
columnA.setMaxWidth(20);
TableColumn columnB= table.getColumn("Start");
columnB.setMinWidth(80);
columnB.setMaxWidth(90);
TableColumn columnC= table.getColumn("End");
columnC.setMinWidth(80);
columnC.setMaxWidth(90);
JPanel textFiled = new JPanel(new GridBagLayout());
GridBagConstraints co = new GridBagConstraints();
co.fill = GridBagConstraints.HORIZONTAL;
co.gridx =0;
co.gridy =0;
co.weightx=0.5;
co.weighty=1;
co.gridheight=0;
co.gridwidth=0;
co.ipadx=900;
co.ipady=80;
co.anchor = GridBagConstraints.PAGE_START;
co.insets = new Insets(100, 0, 5, 0);
textFiled.add(enterText,co);
JPanel p = new JPanel();
p.add(VideoOpration.c);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
add(textFiled, BorderLayout.NORTH);
add(p, BorderLayout.WEST);
//Container cp = getContentPane();
//cp.add(videoCon);
itemOpenVideo.addActionListener(new MenuBarMethod());
}
public class MenuBarMethod implements ActionListener{
@Override
public void actionPerformed(ActionEvent a){
Object buttonPressed=a.getSource();
if(buttonPressed.equals(itemOpenVideo)){
ourFileSelector.setFileSelectionMode(JFileChooser.FILES_ONLY);
ourFileSelector.showSaveDialog(null);
ourFile = ourFileSelector.getSelectedFile();
mediaPath = ourFile.getAbsolutePath();
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}
}
}
}
* "это всегда дает ошибку" * 1) Всегда копировать/вставить ошибку & выход исключение. 2) Чтобы получить более эффективную помощь, отправьте сообщение [MCVE] (http://stackoverflow.com/help/mcve). - BTW - имя класса 'VideoOpration' должно быть' VideoOperation' для правильной орфографии. –
нет ошибки с этим кодом вещь я не знаю, как поставить видео в jpanel в главном кадре –
@peeskillet вы можете взглянуть на этот код –