Hi, I'd like to use my program to take a selected file (from the first batch of code) and play it using the player made in the second lot of code here.
I was wondering if anyone can see where I'm going wrong?
Ive removed the file path but that wasnt the issue
I was wondering if anyone can see where I'm going wrong?
Ive removed the file path but that wasnt the issue
Code:
public VideoListFrame() {
setTitle("Video List");
setClosable(true);
setMaximizable(false);
setIconifiable(false);
setResizable(false);
setBounds(0,0,100,10);
setSize(100,10);
topPanelv = new JPanel();
topPanelv.setLayout( new BorderLayout() );
getContentPane().add( topPanelv, BorderLayout.CENTER);
videolist = new JList(vidlist);
topPanelv.add(videolist);
videolist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
videolist.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
List value = (List)videolist.getSelectedValue();
try {
video1 = (String)value.getVideo();
System.out.println("0");
MainVideo vid = new MainVideo();
System.out.println("1");
String videoplayer = vid.videofile;
System.out.println("2");
vid.videofile = video1;
System.out.println("3");
vid.setVisible(true);
Main.desktop.add(vid);
System.out.println(video1);
}
catch( Exception e ) {
JOptionPane.showMessageDialog(VideoListFrame.this, e, "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
});
}
public void mouseClicked(MouseEvent event) {
// On single right click show popup menu
if((event.getClickCount() == 1) && (event.getModifiers() & InputEvent.BUTTON3_MASK) !=0) {
// popup.show(this, event.getX(), event.getY());
}
}
public void mouseReleased(MouseEvent event){}
public void mousePressed(MouseEvent event){}
public void mouseExited(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
private List[] vidlist = {
new List("Water Waves", "file:///(filepath here)"),
};
class List {
public List(String n, String v) {
name = n;
video = v;
}
public String toString() {
return name;
}
public String getVideo() {
return video;
}
private String name;
private String video;
}
}
Code:
class MainVideo extends JInternalFrame {
private JPanel topPanelV;
private JEditorPane textFrame;
private JScrollPane scrollPane;
private static MainVideo instance;
protected Player player;
public String videofile;
private File file = new File(videofile);
public MainVideo() {
setTitle("Video");
setClosable(true);
setMaximizable(true);
setIconifiable(true);
instance=null;
initComponents();
topPanelV = new JPanel();
topPanelV.setBackground(new Color(255, 255, 169));
topPanelV.setLayout( null);
getContentPane().add( topPanelV, BorderLayout.CENTER);
}
public static MainVideo getInstance(){
if (instance==null)
instance=new MainVideo();
return instance;
}
private void initComponents() {
setSize(300, 300);
file = new File(videofile);
show();
createPlayer();
}
/** Creates new form PlayClip */
private void createPlayer() {
if (file == null) {
return;
}
removePreviousPlayer();
try {
//create a new player and add listener
player = Manager.createPlayer(file.toURL() );
player.addControllerListener(new EventHandler() );
player.start(); //start player
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid file or location", "Error loading file", JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
}
private void removePreviousPlayer() {
if (player == null )
return;
player.close();
Component visual = player.getVisualComponent();
Component control = player.getControlPanelComponent();
Container c = getContentPane();
if (visual != null)
c.remove(visual);
if (control !=null)
c.remove(control);
}
private class EventHandler implements ControllerListener {
public void controllerUpdate(ControllerEvent e) {
if (e instanceof RealizeCompleteEvent ) {
Container c = getContentPane();
Component visualComponent = player.getVisualComponent();
if (visualComponent != null)
c.add(visualComponent, BorderLayout.CENTER);
Component controlsComponent = player.getControlPanelComponent();
if (controlsComponent != null)
c.add(controlsComponent, BorderLayout.SOUTH);
c.doLayout();
}
}
}
public String getVideo1() {
return videofile;
}
}