Ignore:
Timestamp:
2010-06-05T09:37:55+02:00 (14 years ago)
Author:
guardian
Message:

merge GPS and Video

Location:
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
Files:
4 added
1 deleted
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java

    r21555 r21584  
    1818        private List<WayPoint> ls;
    1919        private WayPoint prev,curr,next;
     20        private WayPoint start;
    2021       
    2122
     
    3536                super();
    3637                this.ls = l;
     38                start=ls.get(0);
    3739                prev=null;
    3840                curr=ls.get(0);
     
    7880                        }
    7981                        else next=null;
    80                        
    8182                }
    8283        }
     
    8687                if ((ls.indexOf(curr)+t>0)&&(ls.indexOf(curr)<ls.size()))
    8788                {
    88                         jump(ls.get(ls.indexOf(curr)+t));
     89                        jump(ls.get(ls.indexOf(curr)+t)); //FIXME here is a bug
    8990                }               
    9091        }
     
    280281        }
    281282
    282         public void pause() {
    283                 // TODO Auto-generated method stub
    284                
    285         }
    286        
     283        public long getRelativeTime()
     284        {
     285                return curr.getTime().getTime()-start.getTime().getTime(); //TODO assumes timeintervall is constant!!!!
     286        }
     287
     288        //jumps to a speciffic time
     289        public void jump(long relTime) {
     290                jump(relTime/1000);             //TODO ugly quick hack 
     291               
     292        }
    287293       
    288294}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java

    r21555 r21584  
    4949public class PositionLayer extends Layer implements MouseListener,MouseMotionListener, KeyListener {
    5050        private List<WayPoint> ls;
    51         private GpsPlayer l;
     51        public GpsPlayer l;
    5252        private Collection<WayPoint> selected;
    5353        private Timer t;
     
    6767                df = new SimpleDateFormat("hh:mm:ss:S");
    6868                Main.map.mapView.addMouseListener(this);
    69                 Main.map.mapView.addMouseMotionListener(this);
    70                 addKeys();                                                             
    71                
    72         }
    73 
    74         //add key bindings for navigate through the track (and if synced trough the video, too)
    75         private void addKeys() {
    76                 Action backward = new AbstractAction() {
    77                         public void actionPerformed(ActionEvent e) {
    78                                 if(l!=null)l.prev();
    79                                 Main.map.mapView.repaint();
    80                         }};
    81                        
    82                 Action forward = new AbstractAction() {
    83                         public void actionPerformed(ActionEvent e) {
    84                                 if(l!=null)l.next();
    85                                 Main.map.mapView.repaint();
    86                         }};
    87                 Action startStop = new AbstractAction() {
    88                         public void actionPerformed(ActionEvent e) {
    89                                 if (t==null)
    90                                 {
    91                                         //start
    92                                         t= new Timer();
    93                                         TimerTask ani=new TimerTask() {                 
    94                                                 @Override
    95                                                 //some cheap animation stuff
    96                                                 public void run() {                             
    97                                                         l.next();
    98                                                         Main.map.mapView.repaint();
    99                                                 }
    100                                         };
    101                                         t.schedule(ani,500,500);
    102                                 }
    103                                 else
    104                                 {
    105                                         //stop
    106                                         t.cancel();
    107                                         t=null;                                 
    108                                 }
    109                         }};
    110                 //TODO custome Shortkey management
    111                 Main.registerActionShortcut(backward, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
    112                 Main.registerActionShortcut(forward, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
    113                 //Main.registerActionShortcut(startStop, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0));
    114         }
     69                Main.map.mapView.addMouseMotionListener(this);                                                 
     70               
     71        }
     72
    11573
    11674        @Override
     
    215173                        if (l.getCurr()!=null){
    216174                        p=Main.map.mapView.getPoint(l.getCurr().getEastNorth());
    217                         icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2);                 
    218                         g.drawString(df.format(l.getCurr().getTime()),p.x,p.y);
    219                         }
    220                 }
     175                        icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2);
     176                        SimpleDateFormat ms=new SimpleDateFormat("mm:ss");
     177                        g.drawString(ms.format(l.getRelativeTime()),p.x,p.y);
     178                        }
     179                }
     180        }
     181       
     182        private void markNearestWayPoints(Point mouse) {
     183                final int MAX=10;
     184                Point p;               
     185                Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX);
     186                //iterate through all possible notes
     187                for(WayPoint n : ls)
     188                {
     189                        p = Main.map.mapView.getPoint(n.getEastNorth());
     190                        if (rect.contains(p))
     191                        {                               
     192                                selected.add(n);
     193                        }
     194                       
     195                }       
     196        }
     197       
     198        private WayPoint getNearestWayPoint(Point mouse)
     199        {
     200                final int MAX=10;
     201                Point p;
     202                Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX);
     203                //iterate through all possible notes
     204                for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP?
     205                {
     206                        p = Main.map.mapView.getPoint(n.getEastNorth());
     207                        if (rect.contains(p))
     208                        {                               
     209                                return n;
     210                        }
     211                       
     212                }
     213                return null;
     214               
     215        }
     216       
     217        @Override
     218        public void visitBoundingBox(BoundingXYVisitor arg0) {
     219                // TODO dunno what to do here
     220
     221        }
     222
     223        //mark selected points
     224        public void mouseClicked(MouseEvent e) {               
     225        }
     226
     227        public void mouseEntered(MouseEvent arg0) {     
     228        }
     229
     230        public void mouseExited(MouseEvent arg0) {
     231        }
     232
     233        public void mousePressed(MouseEvent e) {
     234                if(e.getButton() == MouseEvent.BUTTON1) {
     235                        //is it on the cam icon?
     236                        if (l.getCurr()!=null)
     237                        {
     238                                if (getIconRect().contains(e.getPoint()))
     239                                {
     240                                        mouse=e.getPoint();
     241                                        dragIcon=true;
     242                                        //ani.cancel();
     243                                }
     244                        }
     245                }
     246               
     247        }
     248
     249        public void mouseReleased(MouseEvent e) {
     250               
     251                //only on leftclicks of our layer
     252                if(e.getButton() == MouseEvent.BUTTON1) {
     253                        if(dragIcon)
     254                        {
     255                                dragIcon=false;
     256                        }
     257                        else
     258                        {
     259                                //JOptionPane.showMessageDialog(Main.parent,"test");
     260                                markNearestWayPoints(e.getPoint());
     261                                WayPoint wp = getNearestWayPoint(e.getPoint());
     262                                if(wp!=null)
     263                                {
     264                                        l.jump(wp);                     
     265                                }
     266                        }
     267                        Main.map.mapView.repaint();
     268                }
     269               
     270        }
     271       
     272       
     273        public void mouseDragged(MouseEvent e) {               
     274                if(dragIcon)
     275                {                       
     276                        mouse=e.getPoint();
     277                        //restrict to GPS track
     278                        iconPosition=l.getInterpolatedWaypoint(mouse);
     279
     280                        Main.map.mapView.repaint();
     281                }
     282        }
     283
     284        private Rectangle getIconRect()
     285        {
     286                Point p = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
     287                return new Rectangle(p.x-icon.getIconWidth()/2,p.y-icon.getIconHeight()/2,icon.getIconWidth(),icon.getIconHeight());
     288        }
     289       
     290        public void mouseMoved(MouseEvent e) {         
     291               
     292                if (l.getCurr()!=null)
     293                {                                               
     294                        if (getIconRect().contains(e.getPoint()))
     295                        {
     296                                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
     297                        }
     298                        else
     299                        {
     300                                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     301                        }
     302                }
     303               
     304        }
     305
     306        public void keyPressed(KeyEvent e) {
     307                int i;
     308                System.out.println(e.getKeyCode());
     309                switch(e.getKeyCode())
     310                {
     311                        case KeyEvent.VK_RIGHT:
     312                                {
     313                                        l.jump(1);
     314                                };break;
     315                        case KeyEvent.VK_LEFT:
     316                        {
     317                                l.jump(-1);
     318
     319                        };break;
     320                        case KeyEvent.VK_SPACE:
     321                        {
     322                                ani.cancel();
     323                        }
     324                }
     325               
     326        }
     327
     328        public void keyReleased(KeyEvent e) {
     329                // TODO Auto-generated method stub
     330               
     331        }
     332
     333        public void keyTyped(KeyEvent e) {
     334                // TODO Auto-generated method stub
     335               
    221336        }
    222337       
     
    236351                        };
    237352                        t.schedule(ani,500,500);
     353                        //and video
     354                       
    238355                }
    239356                else
     
    245362        }
    246363
    247         private void markNearestWayPoints(Point mouse) {
    248                 final int MAX=10;
    249                 Point p;               
    250                 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX);
    251                 //iterate through all possible notes
    252                 for(WayPoint n : ls)
    253                 {
    254                         p = Main.map.mapView.getPoint(n.getEastNorth());
    255                         if (rect.contains(p))
    256                         {                               
    257                                 selected.add(n);
    258                         }
    259                        
    260                 }       
    261         }
    262        
    263         private WayPoint getNearestWayPoint(Point mouse)
    264         {
    265                 final int MAX=10;
    266                 Point p;
    267                 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX);
    268                 //iterate through all possible notes
    269                 for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP?
    270                 {
    271                         p = Main.map.mapView.getPoint(n.getEastNorth());
    272                         if (rect.contains(p))
    273                         {                               
    274                                 return n;
    275                         }
    276                        
    277                 }
    278                 return null;
    279                
    280         }
    281        
    282         @Override
    283         public void visitBoundingBox(BoundingXYVisitor arg0) {
    284                 // TODO dunno what to do here
    285 
    286         }
    287 
    288         //mark selected points
    289         public void mouseClicked(MouseEvent e) {               
    290         }
    291 
    292         public void mouseEntered(MouseEvent arg0) {     
    293         }
    294 
    295         public void mouseExited(MouseEvent arg0) {
    296         }
    297 
    298         public void mousePressed(MouseEvent e) {
    299                 if(e.getButton() == MouseEvent.BUTTON1) {
    300                         //is it on the cam icon?
    301                         if (l.getCurr()!=null)
    302                         {
    303                                 if (getIconRect().contains(e.getPoint()))
    304                                 {
    305                                         mouse=e.getPoint();
    306                                         dragIcon=true;
    307                                         //ani.cancel();
    308                                 }
    309                         }
    310                 }
    311                
    312         }
    313 
    314         public void mouseReleased(MouseEvent e) {
    315                
    316                 //only on leftclicks of our layer
    317                 if(e.getButton() == MouseEvent.BUTTON1) {
    318                         if(dragIcon)
    319                         {
    320                                 dragIcon=false;
    321                         }
    322                         else
    323                         {
    324                                 //JOptionPane.showMessageDialog(Main.parent,"test");
    325                                 markNearestWayPoints(e.getPoint());
    326                                 WayPoint wp = getNearestWayPoint(e.getPoint());
    327                                 if(wp!=null)
    328                                 {
    329                                         l.jump(wp);                     
    330                                 }
    331                         }
    332                         Main.map.mapView.repaint();
    333                 }
    334                
    335         }
    336        
    337        
    338         public void mouseDragged(MouseEvent e) {               
    339                 if(dragIcon)
    340                 {                       
    341                         mouse=e.getPoint();
    342                         //restrict to GPS track
    343                         iconPosition=l.getInterpolatedWaypoint(mouse);
    344 
    345                         Main.map.mapView.repaint();
    346                 }
    347         }
    348 
    349         private Rectangle getIconRect()
    350         {
    351                 Point p = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
    352                 return new Rectangle(p.x-icon.getIconWidth()/2,p.y-icon.getIconHeight()/2,icon.getIconWidth(),icon.getIconHeight());
    353         }
    354        
    355         public void mouseMoved(MouseEvent e) {         
    356                
    357                 if (l.getCurr()!=null)
    358                 {                                               
    359                         if (getIconRect().contains(e.getPoint()))
    360                         {
    361                                 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    362                         }
    363                         else
    364                         {
    365                                 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    366                         }
    367                 }
    368                
    369         }
    370 
    371         public void keyPressed(KeyEvent e) {
    372                 int i;
    373                 System.out.println(e.getKeyCode());
    374                 switch(e.getKeyCode())
    375                 {
    376                         case KeyEvent.VK_RIGHT:
    377                                 {
    378                                         l.jump(1);
    379                                 };break;
    380                         case KeyEvent.VK_LEFT:
    381                         {
    382                                 l.jump(-1);
    383 
    384                         };break;
    385                         case KeyEvent.VK_SPACE:
    386                         {
    387                                 ani.cancel();
    388                         }
    389                 }
    390                
    391         }
    392 
    393         public void keyReleased(KeyEvent e) {
     364
     365        public void backward() {
     366                if(l!=null)l.prev();
     367                Main.map.mapView.repaint();
     368        }
     369       
     370        public void forward() {
     371                if(l!=null)l.next();
     372                Main.map.mapView.repaint();
     373        }
     374
     375
     376        public void loop() {
    394377                // TODO Auto-generated method stub
    395378               
    396379        }
    397380
    398         public void keyTyped(KeyEvent e) {
    399                 // TODO Auto-generated method stub
    400                
    401         }
    402 
    403381}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java

    r21555 r21584  
    44import java.awt.event.ActionEvent;
    55import java.awt.event.KeyEvent;
     6import java.io.File;
     7import java.util.Collections;
     8import java.util.LinkedList;
     9import java.util.List;
    610
    711import javax.swing.JMenu;
     
    1115import org.openstreetmap.josm.Main;
    1216import org.openstreetmap.josm.plugins.*;
    13 import org.openstreetmap.josm.plugins.videomapping.actions.StartStopAction;
    14 import org.openstreetmap.josm.plugins.videomapping.actions.VideoAddAction;
     17import org.openstreetmap.josm.plugins.videomapping.video.GPSVideoPlayer;
    1518import org.openstreetmap.josm.tools.ImageProvider;
     19import org.openstreetmap.josm.tools.Shortcut;
    1620import org.openstreetmap.josm.actions.JosmAction;
    1721import org.openstreetmap.josm.data.gpx.GpxData;
     22import org.openstreetmap.josm.data.gpx.GpxTrack;
     23import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
     24import org.openstreetmap.josm.data.gpx.WayPoint;
    1825import org.openstreetmap.josm.gui.MainMenu;
    1926import org.openstreetmap.josm.gui.MapFrame;
     
    3340          private JMenu VMenu;
    3441          private GpxData GPSTrack;
    35           private VideoAddAction VAdd;
    36           private StartStopAction VStart;
     42          private List<WayPoint> ls;
     43          private JosmAction VAdd,VStart,Vbackward,Vforward,Vloop;
     44          private GPSVideoPlayer video;
     45        private PositionLayer layer;
    3746         
    3847
     
    5362                        VAdd.setEnabled(true);
    5463                        GPSTrack=((GpxLayer) newLayer).data;                   
    55                         VAdd.setGps(GPSTrack);
    5664                        //TODO append to GPS Layer menu
    5765                }
     
    7886        } //well ok we have a local copy of the GPS track....
    7987
     88        //register main controls
    8089        private void addMenuItems() {
    81                 VAdd= new VideoAddAction(this);
    82                 VStart = new StartStopAction();
     90                VAdd= new JosmAction("Sync Video","videomapping","Sync a video against this GPS track",null,false) {
     91
     92                        /**
     93                         *
     94                         */
     95                        private static final long serialVersionUID = 1L;
     96
     97                        public void actionPerformed(ActionEvent arg0) {
     98                                copyGPSLayer();
     99                                layer = new PositionLayer("test",ls);
     100                                Main.main.addLayer(layer);
     101                                enableControlMenus(true);
     102                                video = new GPSVideoPlayer(new File("C:\\temp\\test.mpg"), layer.l);
     103                        }
     104                };
     105                VStart = new JosmAction("play/pause", "audio-playpause", "starts/pauses video playback",
     106                                Shortcut.registerShortcut("videomapping:startstop","",KeyEvent.VK_SPACE, Shortcut.GROUP_MENU), false) {
     107                       
     108                        public void actionPerformed(ActionEvent e) {                                                           
     109                                video.play();                           
     110                                video.jump(605000);
     111                                layer.l.jump(9*60+20);
     112                                layer.pause();
     113                        }
     114                };
     115                Vbackward = new JosmAction("backward", "audio-prev", "jumps n sec back",
     116                                Shortcut.registerShortcut("videomapping:backward","",KeyEvent.VK_NUMPAD4, Shortcut.GROUP_MENU), false) {
     117                       
     118                        public void actionPerformed(ActionEvent e) {
     119                                layer.backward();
     120                                                       
     121                        }
     122                };
     123                Vforward= new JosmAction("forward", "audio-next", "jumps n sec forward",
     124                                Shortcut.registerShortcut("videomapping:forward","",KeyEvent.VK_NUMPAD6, Shortcut.GROUP_MENU), false) {
     125                       
     126                        public void actionPerformed(ActionEvent e) {
     127                                layer.forward();
     128                                                       
     129                        }
     130                };
     131                Vloop= new JosmAction("loop", "clock", "loops n sec around current position",
     132                                Shortcut.registerShortcut("videomapping:loop","",KeyEvent.VK_NUMPAD5, Shortcut.GROUP_MENU), false) {
     133                       
     134                        public void actionPerformed(ActionEvent e) {
     135                                layer.loop();
     136                                                       
     137                        }
     138                };
    83139                VMenu.add(VAdd);
    84140                enableControlMenus(false);
    85141                VMenu.add(VStart);
     142                VMenu.add(Vbackward);
     143                VMenu.add(Vforward);
     144                VMenu.add(Vloop);
    86145        }
    87146       
    88         public void setMyLayer(PositionLayer layer)
    89         {               
    90                 VStart.setLayer(layer);
    91                 enableControlMenus(true);
    92         }
    93147       
     148       
     149        //we can only move on our layer
    94150        private void enableControlMenus(boolean enabled)
    95151        {
    96152                VStart.setEnabled(enabled);
     153                Vbackward.setEnabled(enabled);
     154                Vforward.setEnabled(enabled);
     155                Vloop.setEnabled(enabled);
     156        }
     157       
     158        //make a flat copy
     159        private void copyGPSLayer()
     160        {
     161                ls = new LinkedList<WayPoint>();
     162        for (GpxTrack trk : GPSTrack.tracks) {
     163            for (GpxTrackSegment segment : trk.getSegments()) {
     164                ls.addAll(segment.getWayPoints());
     165            }
     166        }
     167        Collections.sort(ls); //sort basing upon time
    97168        }
    98169  }
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/SimpleVideoPlayer.java

    r21530 r21584  
     1package org.openstreetmap.josm.plugins.videomapping.video;
    12import java.awt.Adjustable;
     3import org.apache.log4j.Logger;
     4
    25import java.awt.BorderLayout;
    36import java.awt.Canvas;
     
    58import java.awt.event.ActionEvent;
    69import java.awt.event.ActionListener;
     10import java.awt.event.WindowEvent;
     11import java.awt.event.WindowListener;
    712import java.beans.PropertyChangeListener;
     13import java.io.File;
     14import java.text.SimpleDateFormat;
     15import java.util.Date;
    816import java.util.Timer;
    917import java.util.TimerTask;
     18import java.util.concurrent.TimeUnit;
     19import java.util.concurrent.Executors;
     20import java.util.concurrent.ScheduledExecutorService;
    1021
    1122import javax.swing.Action;
     
    2637import uk.co.caprica.vlcj.player.MediaPlayer;
    2738import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
     39import uk.co.caprica.vlcj.player.MediaPlayerEventListener;
    2840import uk.co.caprica.vlcj.player.MediaPlayerFactory;
     41import uk.co.caprica.vlcj.player.VideoMetaData;
    2942
    3043//basic class of a videoplayer for one video
    31 public class SimpleVideoPlayer extends JFrame{
     44public class SimpleVideoPlayer extends JFrame implements MediaPlayerEventListener, WindowListener{
    3245        private MediaPlayer mp;
    3346        private Timer t;
     
    3851        private JSlider speed;
    3952        private Canvas scr;
    40        
    41         public SimpleVideoPlayer(JFrame mainwindow) {
     53        private final String[] mediaOptions = {""};
     54        private boolean syncTimeline=false;
     55        private SimpleDateFormat df;
     56        private static final Logger LOG = Logger.getLogger(SimpleVideoPlayer.class);
     57       
     58        public SimpleVideoPlayer() {
    4259                super();
    43                 //TODO new EnvironmentCheckerFactory().newEnvironmentChecker().checkEnvironment();
     60                /*TODO new EnvironmentCheckerFactory().newEnvironmentChecker().checkEnvironment();
     61                 * if(RuntimeUtil.isWindows()) {
     62                                vlcArgs.add("--plugin-path=" + WindowsRuntimeUtil.getVlcInstallDir() + "\\plugins");
     63                        }
     64                 */
    4465                try
    45                 {
    46                         String mediaPath = "C:\\Dokumente und Einstellungen\\g\\Eigene Dateien\\Eigene Videos\\23C3-1610-en-fudging_with_firmware.m4v";
     66                {                       
    4767                        String[] libvlcArgs = {""};
    4868                        String[] standardMediaOptions = {""};
    49                         String[] mediaOptions = {""};
     69                       
    5070                        System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version());
    5171                        //setup Media Player
    5272                        //TODO we have to deal with unloading things....
    5373                        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs);
    54                     FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainwindow);
     74                    FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(this);
    5575                    mp = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy);
    5676                    mp.setStandardMediaOptions(standardMediaOptions);
    57                     //mp.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {});
    5877                    //setup GUI
     78                    setSize(400, 300);
     79                    df = new SimpleDateFormat("hh:mm:ss:S");
    5980                    scr=new Canvas();
    6081                    timeline = new JSlider(0,100,0);
     
    6990                    setLayout();
    7091                        addListeners();
    71                     //embed player
     92                    //embed vlc player
    7293                        scr.setVisible(true);
    7394                        setVisible(true);
    7495                        mp.setVideoSurface(scr);
    75                     mp.playMedia(mediaPath, mediaOptions);
    76                     mainwindow.pack();
     96                        mp.addMediaPlayerEventListener(this);
     97                        mp.pause();
     98                        jump(0);
     99                        //set updater
     100                        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
     101                        executorService.scheduleAtFixedRate(new Syncer(this), 0L, 500L, TimeUnit.MILLISECONDS);
     102                    //setDefaultCloseOperation(EXIT_ON_CLOSE);
     103                        addWindowListener(this);
    77104                }
    78105                catch (NoClassDefFoundError e)
     
    84111                        System.err.println("Unable to find native libvlc library!");
    85112                }
     113               
    86114        }
    87115       
     
    102130                controlsPanel.add(back);
    103131                controlsPanel.add(forward);
    104                 controlsPanel.add(loop);               
     132                controlsPanel.add(loop);
     133                loop.setSelected(false);
    105134        }
    106135
     
    111140                timeline.addChangeListener(new ChangeListener() {
    112141                        public void stateChanged(ChangeEvent e) {
    113                                 if(!timeline.getValueIsAdjusting())
     142                                if(!syncTimeline) //only if user moves the slider by hand
    114143                                {
    115                                         //recalc to 0.x percent value
    116                                         mp.setPosition((float)timeline.getValue() / 100.0f);
     144                                        if(!timeline.getValueIsAdjusting()) //and the slider is fixed
     145                                        {
     146                                                //recalc to 0.x percent value
     147                                                mp.setPosition((float)timeline.getValue()/100.0f);
     148                                        }                                       
    117149                                }
    118150                        }
     
    120152               
    121153                play.addActionListener(new ActionListener() {
     154                       
    122155                        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();                             
     156                                if(mp.isPlaying()) mp.stop(); else mp.play();                           
    132157                        }
    133158                });
     
    137162                        public void actionPerformed(ActionEvent arg0) {
    138163                                mp.setTime((long) (mp.getTime()-JUMP_LENGTH));
     164                                //jump(600000); //10,05
    139165                               
    140166                        }
     
    152178
    153179                        public void actionPerformed(ActionEvent arg0) {
    154                         if(!loop.getModel().isPressed())
     180                        if(!loop.isSelected())
     181                        {
     182                                t.cancel();
     183                        }
     184                        else                   
    155185                        {
    156186                                final long resetpoint=(long) mp.getTime()-LOOP_LENGTH/2;
     
    165195                                t.schedule(ani,LOOP_LENGTH/2,LOOP_LENGTH); //first run a half looptime till reset       
    166196                                }
    167                         else
    168                         {
    169                                 t.cancel();
    170                         }
    171197                        }
    172198                });
     
    175201                       
    176202                        public void stateChanged(ChangeEvent arg0) {
    177                                 // TODO get integrated with future VLCj relase
     203                                // TODO change playback speed
    178204                               
    179205                        }
     
    181207               
    182208        }
     209
     210        public void finished(MediaPlayer arg0) {
     211                // TODO Auto-generated method stub
     212               
     213        }
     214
     215        public void lengthChanged(MediaPlayer arg0, long arg1) {
     216                // TODO Auto-generated method stub
     217               
     218        }
     219
     220        public void metaDataAvailable(MediaPlayer arg0, VideoMetaData arg1) {
     221                // TODO Auto-generated method stub
     222               
     223        }
     224
     225        public void paused(MediaPlayer arg0) {
     226                // TODO Auto-generated method stub
     227               
     228        }
     229
     230        public void playing(MediaPlayer arg0) {
     231                // TODO Auto-generated method stub
     232               
     233        }
     234
     235        public void positionChanged(MediaPlayer arg0, float arg1) {
     236               
     237        }
     238
     239        public void stopped(MediaPlayer arg0) {
     240                // TODO Auto-generated method stub
     241               
     242        }
     243
     244        public void timeChanged(MediaPlayer arg0, long arg1) {
     245                // TODO Auto-generated method stub
     246               
     247        }
     248       
     249
     250        public void windowActivated(WindowEvent arg0) {
     251                // TODO Auto-generated method stub
     252               
     253        }
     254
     255        public void windowClosed(WindowEvent arg0) {
     256                // TODO Auto-generated method stub
     257               
     258        }
     259
     260        //we have to unload and disconnect to the VLC engine
     261        public void windowClosing(WindowEvent evt) {
     262        if(LOG.isDebugEnabled()) {LOG.debug("windowClosing(evt=" + evt + ")");}
     263        mp.release();
     264        mp = null;
     265        System.exit(0);
     266      }
     267
     268        public void windowDeactivated(WindowEvent arg0) {
     269                // TODO Auto-generated method stub
     270               
     271        }
     272
     273        public void windowDeiconified(WindowEvent arg0) {
     274                // TODO Auto-generated method stub
     275               
     276        }
     277
     278        public void windowIconified(WindowEvent arg0) {
     279                // TODO Auto-generated method stub
     280               
     281        }
     282
     283        public void windowOpened(WindowEvent arg0) {
     284                // TODO Auto-generated method stub
     285               
     286        }       
     287       
     288        public void setFile(File f)
     289        {
     290                String mediaPath = f.getAbsoluteFile().toString();
     291                mp.playMedia(mediaPath, mediaOptions);
     292                jump(8000);
     293                jump(0);
     294                mp.stop();
     295                pack();
     296        }
     297       
     298        public void play()
     299        {
     300                mp.play();
     301        }
     302       
     303        public void jump(long time)
     304        {
     305                /*float pos = (float)mp.getLength()/(float)time;
     306                mp.setPosition(pos);*/
     307                mp.setTime(time);
     308        }
     309       
     310        public long getTime()
     311        {
     312                return mp.getTime();
     313        }
     314       
     315        public float getPosition()
     316        {
     317                return mp.getPosition();
     318        }
     319       
     320        //gets called by the Syncer to update all components
     321        public void updateTime ()
     322        {
     323                if(mp.isPlaying())
     324                {
     325                        setTitle(df.format(new Date(mp.getTime()))+" "+mp.getTime());
     326                        syncTimeline=true;
     327                        timeline.setValue(Math.round(mp.getPosition()*100));
     328                        syncTimeline=false;
     329                }
     330        }
    183331       
    184332
Note: See TracChangeset for help on using the changeset viewer.