Changeset 25765 in osm for applications/editors/josm/plugins/videomapping/src/org
- Timestamp:
- 2011-04-01T16:47:35+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 5 added
- 1 deleted
- 1 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java
r25742 r25765 49 49 50 50 //Here we manage properties and start the other classes 51 public class VideoMappingPlugin extends Plugin implements LayerChangeListener{ 52 private JMenu VMenu,VDeinterlacer; 53 private GpxLayer GpsLayer; 54 private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,VJump,Vfaster,Vslower,Vloop; 55 private JRadioButtonMenuItem VIntBob,VIntNone,VIntLinear; 56 private JCheckBoxMenuItem VCenterIcon,VSubTitles; 57 private JMenuItem VJumpLength,VLoopLength; 58 private GPSVideoPlayer player; 59 private PositionLayer layer; 60 private final String VM_DEINTERLACER="videomapping.deinterlacer"; //where we store settings 61 private final String VM_MRU="videomapping.mru"; 62 private final String VM_AUTOCENTER="videomapping.autocenter"; 63 private final String VM_JUMPLENGTH="videomapping.jumplength"; 64 private final String VM_LOOPLENGTH="videomapping.looplength"; 65 private String deinterlacer; 66 private boolean autocenter; 67 private Integer jumplength,looplength; 68 private String mru; 69 //TODO What more to store during sessions? Size/Position 51 public class VideoPlugin extends Plugin implements LayerChangeListener{ 52 53 public VideoPlugin(PluginInformation info) { 54 super(info); 55 // TODO Auto-generated constructor stub 56 } 57 58 public void activeLayerChange(Layer arg0, Layer arg1) { 59 // TODO Auto-generated method stub 60 61 } 62 63 public void layerAdded(Layer arg0) { 64 // TODO Auto-generated method stub 65 66 } 67 68 public void layerRemoved(Layer arg0) { 69 // TODO Auto-generated method stub 70 71 } 70 72 71 72 public VideoMappingPlugin(PluginInformation info) {73 super(info);74 75 MapView.addLayerChangeListener(this);76 //Register for GPS menu77 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack78 VMenu.setEnabled(false);79 addMenuItems();80 enableControlMenus(false);81 loadSettings();82 applySettings();83 //further plugin informations are provided by build.xml properties84 //NativeLibrary.addSearchPath("vlc", "C:\\Programme\\Video\\VLC"); // this should be the directory that contains libvlc.dll85 NativeLibrary.addSearchPath("libvlc", WindowsRuntimeUtil.getVlcInstallDir());86 }87 88 //only use with GPS and own layers89 public void activeLayerChange(Layer oldLayer, Layer newLayer) {90 VMenu.setEnabled(true);91 if (newLayer instanceof GpxLayer)92 {93 VAdd.setEnabled(true);94 GpsLayer=((GpxLayer) newLayer);95 //TODO append to GPS Layer menu96 }97 }98 99 public void layerAdded(Layer arg0) {100 activeLayerChange(null,arg0);101 }102 103 public void layerRemoved(Layer arg0) {104 if(Main.main.getActiveLayer()==null) VMenu.setEnabled(false);105 } //well ok we have allready a local copy of the GPS track....106 107 //register main controls108 private void addMenuItems() {109 VAdd= new JosmAction(tr("Import Video"),"videomapping",tr("Sync a video against this GPS track"),null,false) {110 private static final long serialVersionUID = 1L;111 112 public void actionPerformed(ActionEvent arg0) {113 JFileChooser fc = new JFileChooser(mru);114 fc.setSelectedFile(new File(mru));115 if(fc.showOpenDialog(Main.main.parent)!=JFileChooser.CANCEL_OPTION)116 {117 //save selected path118 mru=fc.getSelectedFile().getAbsolutePath();119 Main.pref.put(VM_MRU, mru);120 enableControlMenus(true);121 layer = new PositionLayer(fc.getSelectedFile(),GpsLayer);122 Main.main.addLayer(layer);123 //TODO Check here if we can sync allready now124 VAdd.setEnabled(false);125 VRemove.setEnabled(true);126 layer.getVideoPlayer().setSubtitleAction(VSubTitles);127 player=layer.getVideoPlayer();128 }129 }130 131 };132 VRemove= new JosmAction(tr("Remove Video"),"videomapping",tr("removes current video from layer"),null,false) {133 private static final long serialVersionUID = 1L;134 135 public void actionPerformed(ActionEvent arg0) {136 player.removeVideo();137 }138 };139 140 VStart = new JosmAction(tr("Play/Pause"), "audio-playpause", tr("starts/pauses video playback"),141 Shortcut.registerShortcut("videomapping:startstop","Video: "+tr("Play/Pause"),KeyEvent.VK_NUMPAD5, Shortcut.GROUP_DIRECT), false) {142 143 public void actionPerformed(ActionEvent e) {144 if(player.playing()) player.pause(); else player.play();145 }146 };147 Vbackward = new JosmAction(tr("Backward"), "audio-prev", tr("jumps n sec back"),148 Shortcut.registerShortcut("videomapping:backward","Video: "+tr("Backward"),KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) {149 public void actionPerformed(ActionEvent e) {150 player.backward();151 }152 };153 Vforward= new JosmAction(tr("Forward"), "audio-next", tr("jumps n sec forward"),154 Shortcut.registerShortcut("videomapping:forward","Video: "+tr("Forward"),KeyEvent.VK_NUMPAD6, Shortcut.GROUP_DIRECT), false) {155 156 public void actionPerformed(ActionEvent e) {157 player.forward();158 159 }160 };161 Vfaster= new JosmAction(tr("Faster"), "audio-faster", tr("faster playback"),162 Shortcut.registerShortcut("videomapping:faster","Video: "+tr("Faster"),KeyEvent.VK_NUMPAD8, Shortcut.GROUP_DIRECT), false) {163 164 public void actionPerformed(ActionEvent e) {165 player.faster();166 167 }168 };169 Vslower= new JosmAction(tr("Slower"), "audio-slower", tr("slower playback"),170 Shortcut.registerShortcut("videomapping:slower","Video: "+tr("Slower"),KeyEvent.VK_NUMPAD2, Shortcut.GROUP_DIRECT), false) {171 172 public void actionPerformed(ActionEvent e) {173 player.slower();174 175 }176 };177 VJump= new JosmAction(tr("Jump To"), "jumpto", tr("jumps to the entered gps time"),null, false) {178 public void actionPerformed(ActionEvent e) {179 String s;180 try {181 JOptionPane d=new JOptionPane(tr("Jump to"), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);182 final JFormattedTextField inp = new JFormattedTextField(new MaskFormatter("##:##:##"));183 inp.setText(layer.getGPSTime());184 inp.setInputVerifier(new InputVerifier() {185 @Override186 public boolean verify(JComponent input) {187 return false;188 }189 });190 //hack to set the focus191 SwingUtilities.invokeLater(new Runnable() {192 public void run() {193 inp.requestFocus();194 }195 });196 //TODO here we should show the GPS time range to the user197 if(d.showConfirmDialog(Main.main.panel,inp, tr("Jump to"),JOptionPane.OK_CANCEL_OPTION)==JOptionPane.OK_OPTION)198 {199 Date t;200 SimpleDateFormat sdf= new SimpleDateFormat("HH:mm:ss");201 t = sdf.parse(inp.getText());202 if (t!=null)203 {204 player.jumpToGPSTime(t);205 }206 }207 } catch (ParseException e1) {208 // TODO Auto-generated catch block209 e1.printStackTrace();210 }211 212 }213 214 215 };216 Vloop= new JosmAction(tr("Loop"), "loop", tr("loops n sec around current position"),217 Shortcut.registerShortcut("videomapping:loop","Video: "+tr("loop"),KeyEvent.VK_NUMPAD7, Shortcut.GROUP_DIRECT), false) {218 219 public void actionPerformed(ActionEvent e) {220 player.loop();221 222 }223 };224 225 //now the options menu226 VCenterIcon = new JCheckBoxMenuItem(new JosmAction(tr("Keep centered"), null, tr("follows the video icon automaticly"),null, false) {227 228 public void actionPerformed(ActionEvent e) {229 autocenter=VCenterIcon.isSelected();230 player.setAutoCenter(autocenter);231 applySettings();232 saveSettings();233 234 }235 });236 //now the options menu237 VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), null, tr("Show subtitles in video"),null, false) {238 239 public void actionPerformed(ActionEvent e) {240 player.toggleSubtitles();241 242 }243 });244 245 VJumpLength = new JMenuItem(new JosmAction(tr("Jump length"), null, tr("Set the length of a jump"),null, false) {246 247 public void actionPerformed(ActionEvent e) {248 Object[] possibilities = {"200", "500", "1000", "2000", "10000"};249 String s = (String)JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Jump length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,jumplength);250 jumplength=Integer.getInteger(s);251 applySettings();252 saveSettings();253 }254 });255 256 VLoopLength = new JMenuItem(new JosmAction(tr("Loop length"), null, tr("Set the length around a looppoint"),null, false) {257 258 public void actionPerformed(ActionEvent e) {259 Object[] possibilities = {"500", "1000", "3000", "5000", "10000"};260 String s = (String)JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Loop length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,looplength);261 looplength=Integer.getInteger(s);262 applySettings();263 saveSettings();264 265 }266 });267 268 VDeinterlacer= new JMenu("Deinterlacer");269 VIntNone= new JRadioButtonMenuItem(new JosmAction(tr("none"), null, tr("no deinterlacing"),null, false) {270 271 public void actionPerformed(ActionEvent e) {272 deinterlacer=null;273 applySettings();274 saveSettings();275 }276 });277 VIntBob= new JRadioButtonMenuItem(new JosmAction("bob", null, tr("deinterlacing using line doubling"),null, false) {278 279 public void actionPerformed(ActionEvent e) {280 deinterlacer="bob";281 applySettings();282 saveSettings();283 }284 });285 VIntLinear= new JRadioButtonMenuItem(new JosmAction("linear", null, tr("deinterlacing using linear interpolation"),null, false) {286 287 public void actionPerformed(ActionEvent e) {288 deinterlacer="linear";289 applySettings();290 saveSettings();291 }292 });293 VDeinterlacer.add(VIntNone);294 VDeinterlacer.add(VIntBob);295 VDeinterlacer.add(VIntLinear);296 297 VMenu.add(VAdd);298 VMenu.add(VStart);299 VMenu.add(Vbackward);300 VMenu.add(Vforward);301 VMenu.add(Vfaster);302 VMenu.add(Vslower);303 VMenu.add(Vloop);304 VMenu.add(VJump);305 VMenu.addSeparator();306 VMenu.add(VCenterIcon);307 VMenu.add(VJumpLength);308 VMenu.add(VLoopLength);309 VMenu.add(VDeinterlacer);310 VMenu.add(VSubTitles);311 312 }313 314 315 //we can only work on our own layer316 private void enableControlMenus(boolean enabled)317 {318 VStart.setEnabled(enabled);319 Vbackward.setEnabled(enabled);320 Vforward.setEnabled(enabled);321 Vloop.setEnabled(enabled);322 Vfaster.setEnabled(enabled);323 Vslower.setEnabled(enabled);324 VJump.setEnabled(enabled);325 326 }327 328 //load all properties or set defaults329 private void loadSettings() {330 String temp;331 temp=Main.pref.get(VM_AUTOCENTER);332 if((temp!=null)&&(temp.length()!=0))autocenter=Boolean.getBoolean(temp); else autocenter=false;333 temp=Main.pref.get(VM_DEINTERLACER);334 if((temp!=null)&&(temp.length()!=0)) deinterlacer=Main.pref.get(temp);335 temp=Main.pref.get(VM_JUMPLENGTH);336 if((temp!=null)&&(temp.length()!=0)) jumplength=Integer.valueOf(temp); else jumplength=1000;337 temp=Main.pref.get(VM_LOOPLENGTH);338 if((temp!=null)&&(temp.length()!=0)) looplength=Integer.valueOf(temp); else looplength=6000;339 temp=Main.pref.get(VM_MRU);340 if((temp!=null)&&(temp.length()!=0)) mru=Main.pref.get(VM_MRU);else mru=System.getProperty("user.home");341 }342 343 private void applySettings(){344 //Internals345 if(player!=null)346 {347 player.setAutoCenter(autocenter);348 player.setDeinterlacer(deinterlacer);349 player.setJumpLength(jumplength);350 player.setLoopLength(looplength);351 }352 //GUI353 VCenterIcon.setSelected(autocenter);354 VIntNone.setSelected(true);355 if(deinterlacer=="bob")VIntBob.setSelected(true);356 if(deinterlacer=="linear")VIntLinear.setSelected(true);357 358 }359 360 private void saveSettings(){361 Main.pref.put(VM_AUTOCENTER, autocenter);362 Main.pref.put(VM_DEINTERLACER, deinterlacer);363 Main.pref.put(VM_JUMPLENGTH, jumplength.toString());364 Main.pref.put(VM_LOOPLENGTH, looplength.toString());365 }366 73 367 74 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPositionLayer.java
r25742 r25765 36 36 37 37 //Basic rendering and GPS layer interaction 38 public class PositionLayer extends Layer implements MouseListener,MouseMotionListener { 39 private List<WayPoint> ls; 40 private List<WayPoint> ipos; 41 public GpsPlayer gps; 42 private boolean dragIcon=false; //do we move the icon by hand? 43 private WayPoint iconPosition; 44 private Point mouse; 45 private ImageIcon icon; 46 private SimpleDateFormat gpsTimeCode; 47 public GPSVideoPlayer gpsVP; 48 49 public PositionLayer(File video, GpxLayer GpsLayer) { 50 super(video.getName()); 51 ls=copyGPSLayer(GpsLayer.data); //TODO This might be outsourced to a seperated track 52 gps= new GpsPlayer(ls); 53 icon = new ImageIcon("images/videomapping.png"); 54 gpsTimeCode= new SimpleDateFormat("HH:mm:ss");//TODO replace with DF small 55 Main.map.mapView.addMouseListener(this); 56 Main.map.mapView.addMouseMotionListener(this); 57 gpsVP = new GPSVideoPlayer(video, gps); 58 gps.goTo(0); 59 ipos=gps.interpolate(); 60 iconPosition=gps.getCurr(); 61 } 62 63 //make a flat copy 64 private List<WayPoint> copyGPSLayer(GpxData route) 65 { 66 ls = new LinkedList<WayPoint>(); 67 for (GpxTrack trk : route.tracks) { 68 for (GpxTrackSegment segment : trk.getSegments()) { 69 ls.addAll(segment.getWayPoints()); 70 } 71 } 72 Collections.sort(ls); //sort basing upon time 73 return ls; 74 } 38 public class VideoPositionLayer extends Layer implements MouseListener,MouseMotionListener { 75 39 76 77 @Override 78 public Icon getIcon() { 79 return icon; 80 } 81 82 @Override 83 public Object getInfoComponent() { 84 String temp; 85 String sep=System.getProperty("line.separator"); 86 temp=tr("{0} {1}% of GPS track",gpsVP.getVideo().getName(),gpsVP.getCoverage()*10+sep); 87 temp=temp+gpsVP.getNativePlayerInfos(); 88 return temp; 89 } 90 91 @Override 92 public Action[] getMenuEntries() { 93 return new Action[]{ 94 LayerListDialog.getInstance().createActivateLayerAction(this), 95 LayerListDialog.getInstance().createShowHideLayerAction(), 96 LayerListDialog.getInstance().createDeleteLayerAction(), 97 SeparatorLayerAction.INSTANCE, 98 //TODO here my stuff 99 SeparatorLayerAction.INSTANCE, 100 new LayerListPopup.InfoAction(this)};//TODO here infos about the linked videos 40 public VideoPositionLayer(String name) { 41 super(name); 42 // TODO Auto-generated constructor stub 101 43 } 102 44 103 45 @Override 46 public Icon getIcon() { 47 // TODO Auto-generated method stub 48 return null; 49 } 104 50 51 @Override 52 public Object getInfoComponent() { 53 // TODO Auto-generated method stub 54 return null; 55 } 105 56 106 @Override 107 public String getToolTipText() { 108 return tr("Shows current position in the video"); 109 } 57 @Override 58 public Action[] getMenuEntries() { 59 // TODO Auto-generated method stub 60 return null; 61 } 110 62 111 // no merging necessary 112 @Override 113 public boolean isMergable(Layer arg0) { 114 return false;115 63 @Override 64 public String getToolTipText() { 65 // TODO Auto-generated method stub 66 return null; 67 } 116 68 117 @Override 118 public void mergeFrom(Layer arg0) { 119 120 } 69 @Override 70 public boolean isMergable(Layer arg0) { 71 // TODO Auto-generated method stub 72 return false; 73 } 121 74 122 123 124 @Override 125 //Draw the current position, infos, waypoints 126 public void paint(Graphics2D g, MapView map, Bounds bound) { 127 Point p; 128 //TODO Source out redundant calculations 129 //draw all GPS points 130 g.setColor(Color.YELLOW); //new Color(0,255,0,128) 131 for(WayPoint n: ls) { 132 p = Main.map.mapView.getPoint(n.getEastNorth()); 133 g.drawOval(p.x - 2, p.y - 2, 4, 4); 134 } 135 //draw synced points 136 g.setColor(Color.GREEN); 137 for(WayPoint n: ls) { 138 if(n.attr.containsKey("synced")) 139 { 140 p = Main.map.mapView.getPoint(n.getEastNorth()); 141 g.drawOval(p.x - 2, p.y - 2, 4, 4); 142 } 143 } 144 //draw current segment points 145 g.setColor(Color.YELLOW); 146 if(gps.getPrev()!=null) 147 { 148 p = Main.map.mapView.getPoint(gps.getPrev().getEastNorth()); 149 g.drawOval(p.x - 2, p.y - 2, 4, 4); 150 Point p2 = Main.map.mapView.getPoint(gps.getCurr().getEastNorth()); 151 g.drawLine(p.x, p.y, p2.x, p2.y); 152 } 153 if(gps.getNext()!=null) 154 { 155 p = Main.map.mapView.getPoint(gps.getNext().getEastNorth()); 156 g.drawOval(p.x - 2, p.y - 2, 4, 4); 157 Point p2 = Main.map.mapView.getPoint(gps.getCurr().getEastNorth()); 158 g.drawLine(p.x, p.y, p2.x, p2.y); 159 } 160 //draw interpolated points 161 g.setColor(Color.CYAN); 162 g.setBackground(Color.CYAN); 163 //LinkedList<WayPoint> ipo=(LinkedList<WayPoint>) gps.getInterpolatedLine(5); 164 for (WayPoint wp : ipos) { 165 p=Main.map.mapView.getPoint(wp.getEastNorth()); 166 g.fillArc(p.x, p.y, 4, 4, 0, 360); 167 //g.drawOval(p.x - 2, p.y - 2, 4, 4); 168 } 169 //draw cam icon 170 g.setColor(Color.RED); 171 if(dragIcon) 172 { 173 if(iconPosition!=null) 174 { 175 p=Main.map.mapView.getPoint(iconPosition.getEastNorth()); 176 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 177 //g.drawString(mins.format(iconPosition.getTime()),p.x-10,p.y-10); //TODO when synced we might wan't to use a different layout 178 g.drawString(gpsTimeCode.format(iconPosition.getTime()),p.x-15,p.y-15); 179 } 180 } 181 else 182 { 183 if (gps.getCurr()!=null){ 184 p=Main.map.mapView.getPoint(gps.getIPO().getEastNorth()); 185 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 186 g.drawString(gpsTimeCode.format(gps.getCurr().getTime()),p.x-15,p.y-15); 187 } 188 } 189 } 190 191 //finds the first waypoint that is nearby the given point 192 private WayPoint getNearestWayPoint(Point mouse) 193 { 194 final int MAX=10; 195 Point p; 196 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX); 197 //iterate through all possible notes 198 for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP? Hashmaps? Divide and Conquer? 199 { 200 p = Main.map.mapView.getPoint(n.getEastNorth()); 201 if (rect.contains(p)) 202 { 203 return n; 204 } 205 206 } 207 return null; 208 209 } 210 211 //upper left corner like rectangle 212 private Rectangle getIconRect() 213 { 214 Point p = Main.map.mapView.getPoint(gps.getCurr().getEastNorth()); 215 return new Rectangle(p.x-icon.getIconWidth()/2,p.y-icon.getIconHeight()/2,icon.getIconWidth(),icon.getIconHeight()); 216 } 217 218 219 @Override 220 public void visitBoundingBox(BoundingXYVisitor arg0) { 221 // TODO don't know what to do here 222 223 } 224 225 public void mouseClicked(MouseEvent e) { 226 } 227 228 public void mouseEntered(MouseEvent arg0) { 229 } 230 231 public void mouseExited(MouseEvent arg0) { 232 } 233 234 //init drag&drop 235 public void mousePressed(MouseEvent e) { 236 if(e.getButton() == MouseEvent.BUTTON1) { 237 //is it on the cam icon? 238 if (gps.getCurr()!=null) 239 { 240 if (getIconRect().contains(e.getPoint())) 241 { 242 mouse=e.getPoint(); 243 dragIcon=true; 244 } 245 } 246 } 247 248 } 249 250 // 251 public void mouseReleased(MouseEvent e) { 252 //only leftclicks on our layer 253 if(e.getButton() == MouseEvent.BUTTON1) { 254 if(dragIcon) 255 { 256 dragIcon=false; 257 } 258 else 259 { 260 //simple click 261 WayPoint wp = getNearestWayPoint(e.getPoint()); 262 if(wp!=null) 263 { 264 //jump if unsynced 265 if (gpsVP.isSynced()) 266 { 267 //jump if we know position 268 if(wp.attr.containsKey("synced")) 269 { 270 gps.goTo(wp); 271 if(gpsVP!=null) gpsVP.jumpToGPSTime(new Date(gps.getRelativeTime())); //call videoplayers to set right position 272 } 273 } 274 else 275 { 276 //otherwise let user mark possible sync point 277 gps.goTo(wp); 278 } 279 280 } 281 } 282 Main.map.mapView.repaint(); 283 } 284 285 } 286 287 //slide and restrict during movement 288 public void mouseDragged(MouseEvent e) { 289 if(dragIcon) 290 { 291 mouse=e.getPoint(); 292 //restrict to GPS track 293 iconPosition=gps.getInterpolatedWaypoint(mouse); 294 Main.map.mapView.repaint(); 295 } 296 } 297 298 //visualize drag&drop 299 public void mouseMoved(MouseEvent e) { 300 if (gps.getCurr()!=null) 301 { 302 if (getIconRect().contains(e.getPoint())) 303 { 304 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 305 } 306 else 307 { 308 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 309 } 310 } 311 312 } 313 314 public void setVideopPlayer(GPSVideoPlayer player) { 315 gpsVP=player; 75 @Override 76 public void mergeFrom(Layer arg0) { 77 // TODO Auto-generated method stub 316 78 317 79 } 318 319 public GPSVideoPlayer getVideoPlayer() 320 { 321 return gpsVP; 80 81 @Override 82 public void paint(Graphics2D arg0, MapView arg1, Bounds arg2) { 83 // TODO Auto-generated method stub 84 322 85 } 323 324 public String getGPSTime() 325 { 326 return gpsTimeCode.format(iconPosition.getTime()); 86 87 @Override 88 public void visitBoundingBox(BoundingXYVisitor arg0) { 89 // TODO Auto-generated method stub 90 327 91 } 92 93 public void mouseClicked(MouseEvent arg0) { 94 // TODO Auto-generated method stub 95 96 } 97 98 public void mouseEntered(MouseEvent arg0) { 99 // TODO Auto-generated method stub 100 101 } 102 103 public void mouseExited(MouseEvent arg0) { 104 // TODO Auto-generated method stub 105 106 } 107 108 public void mousePressed(MouseEvent arg0) { 109 // TODO Auto-generated method stub 110 111 } 112 113 public void mouseReleased(MouseEvent arg0) { 114 // TODO Auto-generated method stub 115 116 } 117 118 public void mouseDragged(MouseEvent arg0) { 119 // TODO Auto-generated method stub 120 121 } 122 123 public void mouseMoved(MouseEvent arg0) { 124 // TODO Auto-generated method stub 125 126 } 127 328 128 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideo.java
r25244 r25765 3 3 4 4 // a specific synced video 5 public class GPSVideoFile extends File{ 6 public long offset; //time difference in ms between GPS and Video track 7 8 public GPSVideoFile(File f, long offset) { 9 super(f.getAbsoluteFile().toString()); 10 this.offset=offset; 11 } 5 public class GPSVideo { 6 12 7 13 8 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java
r25742 r25765 22 22 public class GPSVideoPlayer 23 23 { 24 Timer t;25 TimerTask updateGPS; //sync GPS position here26 private GpsPlayer gps;27 private SimpleVideoPlayer video;28 private JButton syncBtn;29 private GPSVideoFile file;30 private boolean synced=false; //do we playback the players together?31 private JCheckBoxMenuItem subtTitleComponent;32 24 33 34 public GPSVideoPlayer(File f, final GpsPlayer pl) {35 super();36 this.gps = pl;37 //test sync38 video = new SimpleVideoPlayer();39 /*40 long gpsT=(9*60+20)*1000;41 long videoT=10*60*1000+5*1000;42 setFile(new GPSVideoFile(f, gpsT-videoT)); */43 setFile(new GPSVideoFile(f, 0L));44 //add Sync Button to the Player45 syncBtn= new JButton("sync");46 syncBtn.setBackground(Color.RED);47 syncBtn.addActionListener(new ActionListener() {48 //do a sync49 public void actionPerformed(ActionEvent e) {50 if (!synced)51 {52 //FIXME doesn't work correctly after a resync53 //determine time offset54 long diff=gps.getRelativeTime()-video.getTime(); //FIXME differenzierter betrachten55 file= new GPSVideoFile(file, diff);56 syncBtn.setBackground(Color.GREEN);57 synced=true;58 markSyncedPoints();59 video.play();60 //gps.play();61 }62 else63 {64 //let user resync again65 synced=false;66 syncBtn.setBackground(null);67 }68 }69 });70 setAsyncMode(true);71 video.addComponent(syncBtn);72 //a observer to communicate73 SimpleVideoPlayer.addObserver(new VideoObserver() { //TODO has o become this74 75 public void playing(long time) {76 //sync the GPS back77 if(synced) {78 gps.jump(getGPSTime(time));79 gps.jumpIPO(getGPSTime(time));80 }81 82 }83 84 public void jumping(long time) {85 86 }87 88 //a push way to set video attirbutes89 public void metadata(long time, boolean subtitles) {90 if(subtTitleComponent!=null) subtTitleComponent.setSelected(subtitles);91 }92 93 });94 t = new Timer();95 }96 97 //marks all points that are covered by video AND GPS track98 private void markSyncedPoints() {99 //GPS or video stream starts first in time?100 WayPoint start,end;101 long t;102 if(gps.getLength()<video.getLength())103 {104 //GPS is within video timeperiod105 start=gps.getWaypoint(0);106 end=gps.getWaypoint(gps.getLength());107 }108 else109 {110 //video is within gps timeperiod111 t=getGPSTime(0);112 if(t<0) t=0;113 start=gps.getWaypoint(t);114 end=gps.getWaypoint(getGPSTime(video.getLength()));115 }116 //mark as synced117 List<WayPoint> ls = gps.getTrack().subList(gps.getTrack().indexOf(start), gps.getTrack().indexOf(end));118 119 for (WayPoint wp : ls) {120 wp.attr.clear();121 wp.attr.put("synced", "true");122 }123 }124 125 public void setAsyncMode(boolean b)126 {127 if(b)128 {129 syncBtn.setVisible(true);130 }131 else132 {133 syncBtn.setVisible(false);134 }135 }136 137 138 public void setFile(GPSVideoFile f)139 {140 141 file=f;142 video.setFile(f.getAbsoluteFile());143 //video.play();144 }145 146 /*147 public void play(long gpsstart)148 {149 //video is already playing150 jumpToGPSTime(gpsstart);151 gps.jump(gpsstart);152 //gps.play();153 }154 */155 156 public void play()157 {158 video.play();159 }160 161 public void pause()162 {163 video.pause();164 }165 166 167 //jumps in video to the corresponding GPS time(xx:yy:zz) not date (external triggered)168 public void jumpToGPSTime(java.util.Date date)169 {170 if(!synced)171 {172 //when not synced we can just move the icon to the right position173 gps.jump(date);174 Main.map.mapView.repaint();175 }176 video.jump(getVideoTime(date.getTime()));177 }178 179 //calc synced timecode from video180 private long getVideoTime(long GPStime)181 {182 return GPStime-file.offset;183 }184 185 //calc corresponding GPS time186 private long getGPSTime(long videoTime)187 {188 return videoTime+file.offset;189 }190 191 192 193 public void setJumpLength(Integer integer) {194 video.setJumpLength(integer);195 196 }197 198 public void setLoopLength(Integer integer) {199 video.setLoopLength(integer);200 201 }202 203 public boolean isSynced()204 {205 return synced;206 }207 208 public void loop() {209 video.loop();210 211 }212 213 public void forward() {214 video.forward();215 216 }217 218 public void backward() {219 video.backward();220 221 }222 223 public void removeVideo() {224 video.removeVideo();225 226 }227 228 public File getVideo() {229 return file;230 }231 232 public float getCoverage() {233 return gps.getLength()/video.getLength();234 }235 236 public void setDeinterlacer(String string) {237 video.setDeinterlacer(string);238 239 }240 241 public void setAutoCenter(boolean selected) {242 gps.setAutoCenter(selected);243 244 }245 246 247 //not called by GPS248 public boolean playing() {249 return video.playing();250 }251 252 253 public String getNativePlayerInfos() {254 return video.getNativePlayerInfos();255 }256 257 public void faster() {258 video.faster();259 260 }261 262 public void slower() {263 video.slower();264 265 }266 267 268 public void toggleSubtitles() {269 video.toggleSubs();270 271 }272 273 public boolean hasSubtitles(){274 return video.hasSubtitles();275 }276 277 public void setSubtitleAction(JCheckBoxMenuItem a)278 {279 subtTitleComponent=a;280 }281 282 public void close()283 {284 video.windowClosing(new WindowEvent(video,1));285 }286 25 287 26 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayer.java
r25742 r25765 9 9 import java.awt.Dimension; 10 10 import java.awt.FlowLayout; 11 import java.awt.HeadlessException; 11 12 import java.awt.event.ActionEvent; 12 13 import java.awt.event.ActionListener; … … 21 22 import java.util.HashSet; 22 23 import java.util.Hashtable ; 24 import java.util.LinkedList; 25 import java.util.List; 23 26 import java.util.Set; 24 27 import java.util.TimeZone; … … 56 59 57 60 //basic class of a videoplayer for one video 58 public class SimpleVideoPlayer extends JFrame implements MediaPlayerEventListener, WindowListener{ 59 private EmbeddedMediaPlayer mp; 60 private Timer t; 61 private JPanel screenPanel,controlsPanel; 61 public class VideoPlayer extends JFrame implements WindowListener, VideosObserver, VideoPlayerObserver{ 62 private static final int notificationIntervall = 1000; 63 private JPanel screenPanel,controlsPanel,canvasPanel; 62 64 private JSlider timeline; 63 65 private JButton play,back,forward; 64 66 private JToggleButton loop,mute; 65 67 private JSlider speed; 66 private Canvas scr; 67 private final String[] mediaOptions = {""}; 68 private boolean syncTimeline=false; 69 private boolean looping=false; 70 private SimpleDateFormat ms; 71 private static final Logger LOG = Logger.getLogger(MediaPlayerFactory.class); 72 private int jumpLength=1000; 73 private int loopLength=6000; 74 private static Set<VideoObserver> observers = new HashSet<VideoObserver>(); //we have to implement our own Observer pattern 75 76 public SimpleVideoPlayer() { 77 super(); 78 try 79 { 80 //some workarounds to detect libVLC and DNA on windows 81 if(RuntimeUtil.isWindows()) { 82 System.setProperty("jna.library.path",WindowsRuntimeUtil.getVlcInstallDir()); //FIXME doesn't work even with this workaround! 83 } 84 System.setProperty("logj4.configuration","file:log4j.xml"); //TODO still unsure if we can't link this to the JOSM log4j instance 85 //we don't need any options 86 String[] libvlcArgs = {""}; 87 String[] standardMediaOptions = {""}; 88 //System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version()); 89 //setup Media Player 90 //TODO we have to deal with unloading things again .... 91 MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs); 92 FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(this); 93 mp = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy); 94 mp.setStandardMediaOptions(standardMediaOptions); 95 //setup GUI 96 setSize(400, 300); //later we apply movie size 97 setAlwaysOnTop(true); 98 createUI(); 99 setLayout(); 100 addListeners(); //registering shortcuts is task of the outer plugin class! 101 //embed vlc player 102 scr.setVisible(true); 103 setVisible(true); 104 mp.setVideoSurface(scr); 105 mp.addMediaPlayerEventListener(this); 106 //mp.pause(); 107 //jump(0); 108 //create updater 109 ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); 110 executorService.scheduleAtFixedRate(new Runnable() { 111 //We have to do syncing in the main thread 112 public void run() { 113 SwingUtilities.invokeLater(new Runnable() { 114 //here we update 115 public void run() { 116 if (isPlaying()) updateTime(); //if the video is seeking we get a mess 117 } 118 }); 119 } 120 }, 0L, 500L, TimeUnit.MILLISECONDS); 121 //setDefaultCloseOperation(EXIT_ON_CLOSE); 122 addWindowListener(this); 68 private DateFormat videoTimeFormat; 69 private VideoEngine videoengine; 70 private long jumpLength; 71 private long loopLength; 72 private Timer loopingTimer; 73 private boolean isManualJump; 74 private Timer notificationTimer; 75 private List<VideoPlayerObserver> observers; 76 77 public VideoPlayer(DateFormat videoTimeFormat) throws HeadlessException { 78 super(); 79 this.videoTimeFormat=videoTimeFormat; 80 //setup playback notifications 81 videoengine=new VideoEngine(this); 82 videoengine.addObserver(this); 83 observers=new LinkedList<VideoPlayerObserver>(); 84 addObserver(this); 85 //setup GUI 86 setSize(400, 300); //later we apply movie size 87 setAlwaysOnTop(true); 88 createUI(); 89 addUI(); 90 addUIListeners(); 91 setVisible(true); 92 setAlwaysOnTop(true); 93 this.addWindowListener(this); 94 } 95 96 public void addVideo(File Videofile) 97 { 98 Video video = new Video(Videofile,new Canvas()); 99 canvasPanel.add(video.canvas); 100 video.canvas.setSize(new Dimension(300, 300)); // will be updated by the video engine itself 101 videoengine.add(video); 102 pack(); 103 startNotificationTimer(); 104 } 105 106 protected void play() { 107 videoengine.play(); 108 109 } 110 111 protected void pause(){ 112 videoengine.pause(); 113 } 114 115 protected void backward() { 116 videoengine.jump(-jumpLength); 117 } 118 119 protected void forward() { 120 videoengine.jump(jumpLength); 121 } 122 123 protected void toggleLooping() { 124 if(loopingTimer==null) 125 { 126 //do reset after loop time experienced 127 final long videoResetTime=(long) videoengine.getCurrentVideoTime()-loopLength/2; 128 TimerTask reset=new TimerTask() { 129 @Override 130 public void run() { 131 videoengine.jumpTo(videoResetTime); 132 } 133 }; 134 loopingTimer= new Timer(); 135 loopingTimer.schedule(reset,loopLength/2,loopLength); 123 136 } 124 catch (NoClassDefFoundError e) 125 { 126 System.err.println(tr("Unable to find JNA Java library!")); 127 } 128 catch (UnsatisfiedLinkError e) 129 { 130 System.err.println(tr("Unable to find native libvlc library!")); 131 } 132 133 } 134 135 private void createUI() { 137 else 138 { 139 loopingTimer.cancel(); 140 loopingTimer=null; 141 } 142 143 } 144 145 //create all normal player controls 146 private void createUI() { 136 147 //setIconImage(); 137 ms = new SimpleDateFormat("hh:mm:ss");138 scr=new Canvas();139 148 timeline = new JSlider(0,100,0); 140 timeline.setMajorTickSpacing(10);141 149 timeline.setMajorTickSpacing(5); 150 timeline.setMinorTickSpacing(1); 142 151 timeline.setPaintTicks(true); 143 //TODO we need Icons instead144 152 play= new JButton(tr("play")); 145 153 back= new JButton("<"); … … 147 155 loop= new JToggleButton(tr("loop")); 148 156 mute= new JToggleButton(tr("mute")); 149 speed = new JSlider( -200,200,0);150 speed.setMajorTickSpacing( 100);157 speed = new JSlider(0,200,100); 158 speed.setMajorTickSpacing(50); 151 159 speed.setPaintTicks(true); 152 160 speed.setOrientation(Adjustable.VERTICAL); 153 161 Hashtable labelTable = new Hashtable (); 154 labelTable.put( new Integer( 0 ), new JLabel("1x") );155 labelTable.put( new Integer( -200 ), new JLabel("-2x") );162 labelTable.put( new Integer( 100 ), new JLabel("1x") ); 163 labelTable.put( new Integer( 50 ), new JLabel("-2x") ); 156 164 labelTable.put( new Integer( 200 ), new JLabel("2x") ); 157 165 speed.setLabelTable( labelTable ); 158 166 speed.setPaintLabels(true); 159 167 } 160 161 //creates a layout like the most mediaplayers are... 162 private void setLayout() { 168 169 //puts all player controls to screen 170 private void addUI() { 171 //create layouts 163 172 this.setLayout(new BorderLayout()); 164 173 screenPanel=new JPanel(); … … 166 175 controlsPanel=new JPanel(); 167 176 controlsPanel.setLayout(new FlowLayout()); 177 canvasPanel=new JPanel(); 178 canvasPanel.setLayout(new FlowLayout()); 168 179 add(screenPanel,BorderLayout.CENTER); 169 180 add(controlsPanel,BorderLayout.SOUTH); 170 181 //fill screen panel 171 screenPanel.add( scr,BorderLayout.CENTER);182 screenPanel.add(canvasPanel,BorderLayout.CENTER); 172 183 screenPanel.add(timeline,BorderLayout.SOUTH); 173 184 screenPanel.add(speed,BorderLayout.EAST); … … 180 191 mute.setSelected(false); 181 192 } 182 183 //add UI functionality 184 private void addListeners() { 193 194 //add UI functionality 195 private void addUIListeners() { 196 197 play.addActionListener(new ActionListener() { 198 public void actionPerformed(ActionEvent arg0) { 199 pause(); 200 } 201 }); 202 203 back.addActionListener(new ActionListener() { 204 205 public void actionPerformed(ActionEvent arg0) { 206 backward(); 207 } 208 }); 209 210 forward.addActionListener(new ActionListener() { 211 212 public void actionPerformed(ActionEvent arg0) { 213 forward(); 214 } 215 }); 216 217 loop.addActionListener(new ActionListener() { 218 219 public void actionPerformed(ActionEvent arg0) { 220 toggleLooping(); 221 } 222 }); 223 224 mute.addActionListener(new ActionListener() { 225 226 public void actionPerformed(ActionEvent arg0) { 227 videoengine.mute(); 228 } 229 }); 230 185 231 timeline.addChangeListener(new ChangeListener() { 186 232 public void stateChanged(ChangeEvent e) { 187 if(!syncTimeline) //only if user moves the slider by hand 188 { 189 if(!timeline.getValueIsAdjusting()) //and the slider is fixed 190 { 191 //recalc to 0.x percent value 192 mp.setPosition((float)timeline.getValue()/100.0f); 193 } 194 } 195 } 196 }); 197 198 play.addActionListener(new ActionListener() { 199 200 public void actionPerformed(ActionEvent arg0) { 201 if(mp.isPlaying()) mp.pause(); else mp.play(); 202 } 203 }); 204 205 back.addActionListener(new ActionListener() { 206 207 public void actionPerformed(ActionEvent arg0) { 208 backward(); 209 } 210 }); 211 212 forward.addActionListener(new ActionListener() { 213 214 public void actionPerformed(ActionEvent arg0) { 215 forward(); 216 } 217 }); 218 219 loop.addActionListener(new ActionListener() { 220 221 public void actionPerformed(ActionEvent arg0) { 222 loop(); 223 } 224 }); 225 226 mute.addActionListener(new ActionListener() { 227 228 public void actionPerformed(ActionEvent arg0) { 229 mute(); 230 } 231 }); 232 233 speed.addChangeListener(new ChangeListener() { 234 233 //skip events, fired by this sliede, one cycle ago 234 if(!isManualJump) 235 { 236 isManualJump=true; 237 videoengine.jumpToPosition((timeline.getValue())); 238 } 239 } 240 241 }); 242 243 speed.addChangeListener(new ChangeListener() { 235 244 public void stateChanged(ChangeEvent arg0) { 236 if(!speed.getValueIsAdjusting()&&(mp.isPlaying())) 237 { 238 int perc = speed.getValue(); 239 float ratio= (float) (perc/400f*1.75); 240 ratio=ratio+(9/8); 241 mp.setRate(ratio); 242 } 243 244 } 245 }); 246 247 } 248 249 public void finished(MediaPlayer arg0) { 250 251 } 252 253 public void lengthChanged(MediaPlayer arg0, long arg1) { 254 255 } 256 257 public void metaDataAvailable(MediaPlayer arg0, VideoMetaData data) { 258 final float perc = 0.5f; 259 Dimension org=data.getVideoDimension(); 260 scr.setSize(new Dimension((int)(org.width*perc), (int)(org.height*perc))); 261 pack(); 262 //send out metadatas to all observers 263 for (VideoObserver o : observers) { 264 o.metadata(0, hasSubtitles()); 265 } 266 } 267 268 public void paused(MediaPlayer arg0) { 269 270 } 271 272 public void playing(MediaPlayer arg0) { 273 274 } 275 276 public void positionChanged(MediaPlayer arg0, float arg1) { 277 278 } 279 280 public void stopped(MediaPlayer arg0) { 281 282 } 283 284 public void timeChanged(MediaPlayer arg0, long arg1) { 285 286 } 287 288 289 public void windowActivated(WindowEvent arg0) { } 290 291 public void windowClosed(WindowEvent arg0) { } 292 293 //we have to unload and disconnect to the VLC engine 294 public void windowClosing(WindowEvent evt) { 295 if(LOG.isDebugEnabled()) {LOG.debug("windowClosing(evt=" + evt + ")");} 296 pause(); 297 //FIXME stop timers etc. 298 mp.release(); 299 mp = null; 300 } 301 302 public void windowDeactivated(WindowEvent arg0) { } 303 304 public void windowDeiconified(WindowEvent arg0) { } 305 306 public void windowIconified(WindowEvent arg0) { } 307 308 public void windowOpened(WindowEvent arg0) { } 309 310 public void setFile(File f) 245 if(!speed.getValueIsAdjusting()) 246 { 247 videoengine.setSpeed(speed.getValue()); 248 } 249 } 250 }); 251 252 } 253 254 public void setJumpLength(long ms) 311 255 { 312 String mediaPath = f.getAbsoluteFile().toString(); 313 mp.playMedia(mediaPath, mediaOptions); 314 pack(); 315 } 316 317 public void play() 256 jumpLength=ms; 257 } 258 259 public void setLoopLength(long ms) 318 260 { 319 mp.play();320 } 321 322 public void jump(long time)261 loopLength=ms; 262 } 263 264 public void addObserver(VideoPlayerObserver observer) 323 265 { 324 /*float pos = (float)mp.getLength()/(float)time; 325 mp.setPosition(pos);*/ 326 mp.setTime(time); 327 } 328 329 public long getTime() 330 { 331 return mp.getTime(); 332 } 333 334 public float getPosition() 335 { 336 return mp.getPosition(); 337 } 338 339 public boolean isPlaying() 340 { 341 return mp.isPlaying(); 342 } 343 344 //gets called by the Syncer thread to update all observers 345 public void updateTime () 346 { 347 if(mp.isPlaying()) 348 { 349 long millis=mp.getTime(); 350 String s = String.format("%02d:%02d:%02d", //dont know why normal Java date utils doesn't format the time right 351 TimeUnit.MILLISECONDS.toHours(millis), 352 TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), 353 TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) 354 ); 355 //setTitle(ms.format(new Time(sec))); 356 setTitle(s); 357 syncTimeline=true; 358 timeline.setValue(Math.round(mp.getPosition()*100)); 359 syncTimeline=false; 360 notifyObservers(mp.getTime()); 361 } 362 } 363 364 //allow externals to extend the ui 365 public void addComponent(JComponent c) 366 { 367 controlsPanel.add(c); 368 pack(); 369 } 370 371 public long getLength() { 372 return mp.getLength(); 373 } 374 375 public void setDeinterlacer(String string) { 376 mp.setDeinterlace(string); 377 378 } 379 380 public void setJumpLength(Integer integer) { 381 jumpLength=integer; 382 383 } 384 385 public void setLoopLength(Integer integer) { 386 loopLength = integer; 387 388 } 389 390 public void loop() { 391 if(looping) 392 { 393 t.cancel(); 394 looping=false; 395 } 396 else 397 { 398 final long resetpoint=(long) mp.getTime()-loopLength/2; 399 TimerTask ani=new TimerTask() { 400 401 @Override 402 public void run() { 403 mp.setTime(resetpoint); 404 } 405 }; 406 t= new Timer(); 407 t.schedule(ani,loopLength/2,loopLength); //first run a half looptime till reset 408 looping=true; 409 } 410 411 } 412 413 protected void mute() { 414 mp.mute(); 415 416 } 417 418 public void forward() { 419 mp.setTime((long) (mp.getTime()+jumpLength)); 420 } 421 422 public void backward() { 423 mp.setTime((long) (mp.getTime()-jumpLength)); 424 425 } 426 427 public void removeVideo() { 428 if (mp.isPlaying()) mp.stop(); 429 mp.release(); 430 431 } 432 433 public void toggleSubs() 434 { 435 //vlc manages it's subtitles in a own list so we have to cycle trough 436 int spu = mp.getSpu(); 437 if(spu > -1) { 438 spu++; 439 if(spu > mp.getSpuCount()) { 440 spu = -1; 441 } 442 } 443 else { 444 spu = 0; 445 } 446 mp.setSpu(spu); 447 } 448 449 public static void addObserver(VideoObserver observer) { 450 451 observers.add(observer); 452 453 } 454 455 456 457 public static void removeObserver(VideoObserver observer) { 458 459 observers.remove(observer); 460 461 } 462 463 private static void notifyObservers(long newTime) { 464 465 for (VideoObserver o : observers) { 466 o.playing(newTime); 467 } 468 469 } 470 471 public String getNativePlayerInfos() { 472 return "VLC "+LibVlc.INSTANCE.libvlc_get_version(); 473 } 474 475 public void faster() { 476 speed.setValue(speed.getValue()+100); 477 478 } 479 480 public void slower() { 481 speed.setValue(speed.getValue()-100); 482 483 } 484 485 public void pause() { 486 if (mp.isPlaying()) mp.pause(); 487 488 } 489 490 public boolean playing() { 491 return mp.isPlaying(); 492 } 493 494 public void error(MediaPlayer arg0) { 495 // TODO Auto-generated method stub 496 497 } 498 499 public void mediaChanged(MediaPlayer arg0) { 500 // TODO Auto-generated method stub 501 502 } 503 504 public boolean hasSubtitles() { 505 if (mp.getSpuCount()==0) return false; else return true; 506 } 507 508 public void backward(MediaPlayer arg0) { 509 // TODO Auto-generated method stub 510 266 observers.add(observer); 267 } 268 269 270 private void startNotificationTimer() { 271 if(notificationTimer==null) 272 { 273 notificationTimer= new Timer(); 274 notificationTimer.schedule(new TimerTask() { 275 @Override 276 public void run() { 277 notifyObservers(); 278 279 } 280 },notificationIntervall,notificationIntervall); 511 281 } 512 513 public void buffering(MediaPlayer arg0) { 514 System.out.println("buffering!"); 515 282 } 283 284 private void notifyObservers() { 285 for (VideoPlayerObserver observer : observers) { 286 observer.update_plays();//TODO hier müssten gleich die Zeiten übergeben werden 516 287 } 517 518 public void forward(MediaPlayer arg0) { 519 // TODO Auto-generated method stub 520 521 } 522 523 public void opening(MediaPlayer arg0) { 524 // TODO Auto-generated method stub 525 System.out.println("opening!"); 526 527 } 528 529 public void pausableChanged(MediaPlayer arg0, int arg1) { 530 // TODO Auto-generated method stub 531 532 } 533 534 public void seekableChanged(MediaPlayer arg0, int arg1) { 535 System.out.println("seeking!"); 536 537 } 538 539 public void snapshotTaken(MediaPlayer arg0, String arg1) { 540 // TODO Auto-generated method stub 541 542 } 543 544 public void titleChanged(MediaPlayer arg0, int arg1) { 545 // TODO Auto-generated method stub 546 547 } 288 } 289 290 public void windowActivated(WindowEvent arg0) { 291 // TODO Auto-generated method stub 292 293 } 294 295 public void windowClosed(WindowEvent arg0) { 296 297 } 298 299 public void windowClosing(WindowEvent arg0) { 300 videoengine.unload(); 301 } 302 303 public void windowDeactivated(WindowEvent arg0) { 304 // TODO Auto-generated method stub 305 306 } 307 308 public void windowDeiconified(WindowEvent arg0) { 309 // TODO Auto-generated method stub 310 311 } 312 313 public void windowIconified(WindowEvent arg0) { 314 // TODO Auto-generated method stub 315 316 } 317 318 public void windowOpened(WindowEvent arg0) { 319 // TODO Auto-generated method stub 320 321 } 322 323 public void update(VideoObserversEvents event) { 324 switch (event) 325 { 326 case resizing: 327 { 328 pack(); 329 break; 330 } 331 case speeding: 332 { 333 speed.setValue(videoengine.getSpeed()); 334 } 335 case jumping: 336 { 337 } 338 } 339 } 340 341 //keep internal controls up to date during playback 342 public void update_plays() { 343 timeline.setValue(videoengine.getPosition()); 344 System.out.println(videoengine.getPosition()); 345 isManualJump=false; 346 347 } 348 548 349 549 350
Note:
See TracChangeset
for help on using the changeset viewer.