| 1 | import java.awt.Adjustable;
|
|---|
| 2 | import java.awt.BorderLayout;
|
|---|
| 3 | import java.awt.Canvas;
|
|---|
| 4 | import java.awt.FlowLayout;
|
|---|
| 5 | import java.awt.event.ActionEvent;
|
|---|
| 6 | import java.awt.event.ActionListener;
|
|---|
| 7 | import java.beans.PropertyChangeListener;
|
|---|
| 8 | import java.util.Timer;
|
|---|
| 9 | import java.util.TimerTask;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.Action;
|
|---|
| 12 | import javax.swing.JButton;
|
|---|
| 13 | import javax.swing.JFrame;
|
|---|
| 14 | import javax.swing.JPanel;
|
|---|
| 15 | import javax.swing.JSlider;
|
|---|
| 16 | import javax.swing.JToggleButton;
|
|---|
| 17 | import javax.swing.event.ChangeEvent;
|
|---|
| 18 | import javax.swing.event.ChangeListener;
|
|---|
| 19 |
|
|---|
| 20 | import org.openstreetmap.josm.Main;
|
|---|
| 21 |
|
|---|
| 22 | import uk.co.caprica.vlcj.binding.LibVlc;
|
|---|
| 23 | import uk.co.caprica.vlcj.check.EnvironmentCheckerFactory;
|
|---|
| 24 | import uk.co.caprica.vlcj.player.DefaultFullScreenStrategy;
|
|---|
| 25 | import uk.co.caprica.vlcj.player.FullScreenStrategy;
|
|---|
| 26 | import uk.co.caprica.vlcj.player.MediaPlayer;
|
|---|
| 27 | import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
|
|---|
| 28 | import uk.co.caprica.vlcj.player.MediaPlayerFactory;
|
|---|
| 29 |
|
|---|
| 30 | //basic class of a videoplayer for one video
|
|---|
| 31 | public class SimpleVideoPlayer extends JFrame{
|
|---|
| 32 | private MediaPlayer mp;
|
|---|
| 33 | private Timer t;
|
|---|
| 34 | private JPanel screenPanel,controlsPanel;
|
|---|
| 35 | private JSlider timeline;
|
|---|
| 36 | private JButton play,back,forward;
|
|---|
| 37 | private JToggleButton loop;
|
|---|
| 38 | private JSlider speed;
|
|---|
| 39 | private Canvas scr;
|
|---|
| 40 |
|
|---|
| 41 | public SimpleVideoPlayer(JFrame mainwindow) {
|
|---|
| 42 | super();
|
|---|
| 43 | //TODO new EnvironmentCheckerFactory().newEnvironmentChecker().checkEnvironment();
|
|---|
| 44 | try
|
|---|
| 45 | {
|
|---|
| 46 | String mediaPath = "C:\\Dokumente und Einstellungen\\g\\Eigene Dateien\\Eigene Videos\\23C3-1610-en-fudging_with_firmware.m4v";
|
|---|
| 47 | String[] libvlcArgs = {""};
|
|---|
| 48 | String[] standardMediaOptions = {""};
|
|---|
| 49 | String[] mediaOptions = {""};
|
|---|
| 50 | System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version());
|
|---|
| 51 | //setup Media Player
|
|---|
| 52 | //TODO we have to deal with unloading things....
|
|---|
| 53 | MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs);
|
|---|
| 54 | FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainwindow);
|
|---|
| 55 | mp = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy);
|
|---|
| 56 | mp.setStandardMediaOptions(standardMediaOptions);
|
|---|
| 57 | //mp.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {});
|
|---|
| 58 | //setup GUI
|
|---|
| 59 | scr=new Canvas();
|
|---|
| 60 | timeline = new JSlider(0,100,0);
|
|---|
| 61 | play= new JButton("play");
|
|---|
| 62 | back= new JButton("<");
|
|---|
| 63 | forward= new JButton(">");
|
|---|
| 64 | loop= new JToggleButton("loop");
|
|---|
| 65 | speed = new JSlider(0,2,1);
|
|---|
| 66 | speed.setPaintTicks(true);
|
|---|
| 67 | speed.setMajorTickSpacing(5);
|
|---|
| 68 | speed.setOrientation(Adjustable.VERTICAL);
|
|---|
| 69 | setLayout();
|
|---|
| 70 | addListeners();
|
|---|
| 71 | //embed player
|
|---|
| 72 | scr.setVisible(true);
|
|---|
| 73 | setVisible(true);
|
|---|
| 74 | mp.setVideoSurface(scr);
|
|---|
| 75 | mp.playMedia(mediaPath, mediaOptions);
|
|---|
| 76 | mainwindow.pack();
|
|---|
| 77 | }
|
|---|
| 78 | catch (NoClassDefFoundError e)
|
|---|
| 79 | {
|
|---|
| 80 | System.err.println("Unable to find JNA Java library!");
|
|---|
| 81 | }
|
|---|
| 82 | catch (UnsatisfiedLinkError e)
|
|---|
| 83 | {
|
|---|
| 84 | System.err.println("Unable to find native libvlc library!");
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | //creates a layout like the most mediaplayers are...
|
|---|
| 89 | private void setLayout() {
|
|---|
| 90 | this.setLayout(new BorderLayout());
|
|---|
| 91 | screenPanel=new JPanel();
|
|---|
| 92 | screenPanel.setLayout(new BorderLayout());
|
|---|
| 93 | controlsPanel=new JPanel();
|
|---|
| 94 | controlsPanel.setLayout(new FlowLayout());
|
|---|
| 95 | add(screenPanel,BorderLayout.CENTER);
|
|---|
| 96 | add(controlsPanel,BorderLayout.SOUTH);
|
|---|
| 97 | //fill screen panel
|
|---|
| 98 | screenPanel.add(scr,BorderLayout.CENTER);
|
|---|
| 99 | screenPanel.add(timeline,BorderLayout.SOUTH);
|
|---|
| 100 | screenPanel.add(speed,BorderLayout.EAST);
|
|---|
| 101 | controlsPanel.add(play);
|
|---|
| 102 | controlsPanel.add(back);
|
|---|
| 103 | controlsPanel.add(forward);
|
|---|
| 104 | controlsPanel.add(loop);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | //add UI functionality
|
|---|
| 108 | private void addListeners() {
|
|---|
| 109 | final float JUMP_LENGTH=1000;
|
|---|
| 110 | final int LOOP_LENGTH=6000;
|
|---|
| 111 | timeline.addChangeListener(new ChangeListener() {
|
|---|
| 112 | public void stateChanged(ChangeEvent e) {
|
|---|
| 113 | if(!timeline.getValueIsAdjusting())
|
|---|
| 114 | {
|
|---|
| 115 | //recalc to 0.x percent value
|
|---|
| 116 | mp.setPosition((float)timeline.getValue() / 100.0f);
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | });
|
|---|
| 120 |
|
|---|
| 121 | play.addActionListener(new ActionListener() {
|
|---|
| 122 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 123 | mp.play();
|
|---|
| 124 |
|
|---|
| 125 | }
|
|---|
| 126 | });
|
|---|
| 127 |
|
|---|
| 128 | play.addActionListener(new ActionListener() {
|
|---|
| 129 |
|
|---|
| 130 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 131 | mp.play();
|
|---|
| 132 | }
|
|---|
| 133 | });
|
|---|
| 134 |
|
|---|
| 135 | back.addActionListener(new ActionListener() {
|
|---|
| 136 |
|
|---|
| 137 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 138 | mp.setTime((long) (mp.getTime()-JUMP_LENGTH));
|
|---|
| 139 |
|
|---|
| 140 | }
|
|---|
| 141 | });
|
|---|
| 142 |
|
|---|
| 143 | forward.addActionListener(new ActionListener() {
|
|---|
| 144 |
|
|---|
| 145 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 146 | mp.setTime((long) (mp.getTime()+JUMP_LENGTH));
|
|---|
| 147 |
|
|---|
| 148 | }
|
|---|
| 149 | });
|
|---|
| 150 |
|
|---|
| 151 | loop.addActionListener(new ActionListener() {
|
|---|
| 152 |
|
|---|
| 153 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 154 | if(!loop.getModel().isPressed())
|
|---|
| 155 | {
|
|---|
| 156 | final long resetpoint=(long) mp.getTime()-LOOP_LENGTH/2;
|
|---|
| 157 | TimerTask ani=new TimerTask() {
|
|---|
| 158 |
|
|---|
| 159 | @Override
|
|---|
| 160 | public void run() {
|
|---|
| 161 | mp.setTime(resetpoint);
|
|---|
| 162 | }
|
|---|
| 163 | };
|
|---|
| 164 | t= new Timer();
|
|---|
| 165 | t.schedule(ani,LOOP_LENGTH/2,LOOP_LENGTH); //first run a half looptime till reset
|
|---|
| 166 | }
|
|---|
| 167 | else
|
|---|
| 168 | {
|
|---|
| 169 | t.cancel();
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | });
|
|---|
| 173 |
|
|---|
| 174 | speed.addChangeListener(new ChangeListener() {
|
|---|
| 175 |
|
|---|
| 176 | public void stateChanged(ChangeEvent arg0) {
|
|---|
| 177 | // TODO get integrated with future VLCj relase
|
|---|
| 178 |
|
|---|
| 179 | }
|
|---|
| 180 | });
|
|---|
| 181 |
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 | }
|
|---|