Revision 2366

tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/VLCPlayer.java (revision 2366)
93 93
		//uncomment to enable VLC logs
94 94
		//Logger.setLevel(Level.TRACE);
95 95
	}
96
	
97
	public EmbeddedMediaPlayer getEmbeddedMediaPlayer() {
98
		return vlcPlayer;
99
	}
96 100

  
97 101
	public VLCPlayer(Composite parent, int style) {
98 102
		super(parent, style);
......
250 254
		rateField.setMaximum(140);
251 255
		rateField.setMinimum(70);
252 256
		rateField.setSelection(100);
253
		rateField.setPageIncrement (5);
257
		rateField.setPageIncrement(5);
254 258

  
255 259
		rateField.addSelectionListener(new SelectionListener() {
256 260
			@Override
......
277 281
		volumeField.setMinimum(0);
278 282
		volumeField.setMaximum(100);
279 283
		volumeField.setSelection(volume);
280
		volumeField.setPageIncrement (5);
284
		volumeField.setPageIncrement(5);
281 285
		volumeField.addSelectionListener(new SelectionListener() {
282 286
			@Override
283 287
			public void widgetSelected(SelectionEvent e) {
......
296 300
		vlcPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {			
297 301
			@Override
298 302
			public void playing(MediaPlayer mediaPlayer) {
299
				if (volumeField != null)
303
				if (volumeField != null) {
300 304
					vlcPlayer.setVolume(volume);
305
				}
301 306
			}
302 307

  
303 308
			@Override
......
312 317

  
313 318
		vlcPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
314 319

  
315
			//			@Override
316
			//			public void videoOutput(MediaPlayer arg0, int arg1) {
317
			//				System.out.println("videoOutput: "+arg1);
318
			//			}
319
			//			
320
			//			@Override
321
			//			public void titleChanged(MediaPlayer arg0, int arg1) {
322
			//				System.out.println("titleChanged: "+arg1);
323
			//			}
324

  
325

  
326 320
			@Override
327 321
			public void timeChanged(MediaPlayer arg0, final long arg1) {
328 322
				time = arg1;
329
				if (previous == time) return;
323
				if (previous == time) {
324
					return;
325
				}
330 326
				previous = time;
331 327

  
332 328
				timeLabel.getDisplay().syncExec(new Runnable() {
333 329
					@Override
334 330
					public void run() {
335
						if (timeRange.isDisposed()) return;
336
						if (!timeRange.isDragMiddleKnob())
331
						if (timeRange.isDisposed()) {
332
							return;
333
						}
334
						if (!timeRange.isDragMiddleKnob()) {
337 335
							timeRange.setMiddleValue((int)time);
336
						}
338 337
						updateTimeLabel();
339 338
						
340
						if (arg1 > end) {
339
						if (arg1 > end && end != start) {
341 340
							//System.out.println("Time > end :"+arg1 +" > "+end);
342 341
							if (repeat) {
343 342
								vlcPlayer.setTime(start);
......
347 346
						}
348 347
					}
349 348
				});
350
				
351
				
352 349
			}
353 350

  
354
			//			@Override
355
			//			public void subItemPlayed(MediaPlayer arg0, int arg1) {
356
			//				System.out.println("subItemPlayed: "+arg1);
357
			//			}
358
			//			
359
			//			@Override
360
			//			public void subItemFinished(MediaPlayer arg0, int arg1) {
361
			//				System.out.println("subItemFinished: "+arg1);
362
			//			}
363
			//			
364
			//			@Override
365
			//			public void stopped(MediaPlayer arg0) {
366
			//				System.out.println("stopped: ");
367
			//			}
368
			//			
369
			//			@Override
370
			//			public void snapshotTaken(MediaPlayer arg0, String arg1) {
371
			//				System.out.println("snapshotTaken: "+arg1);
372
			//			}
373
			//			
374
			//			@Override
375
			//			public void seekableChanged(MediaPlayer arg0, int arg1) {
376
			//				System.out.println("seekableChanged: "+arg1);
377
			//			}
378
			//			
379
			//			@Override
380
			//			public void positionChanged(MediaPlayer arg0, float arg1) {
381
			//				//System.out.println("positionChanged: "+arg1);
382
			//			}
383
			//			
384
			//			@Override
385
			//			public void playing(MediaPlayer arg0) {
386
			//				System.out.println("playing: ");
387
			//			}
388
			//			
389
			//			@Override
390
			//			public void paused(MediaPlayer arg0) {
391
			//				System.out.println("paused: ");
392
			//			}
393
			//			
394
			//			@Override
395
			//			public void pausableChanged(MediaPlayer arg0, int arg1) {
396
			//				System.out.println("pausableChanged: "+arg1);
397
			//			}
398
			//			
399
			//			@Override
400
			//			public void opening(MediaPlayer arg0) {
401
			//				System.out.println("opening: ");
402
			//			}
403
			//			
404
			//			@Override
405
			//			public void newMedia(MediaPlayer arg0) {
406
			//				System.out.println("newMedia: ");
407
			//			}
408
			//						
409
			//			@Override
410
			//			public void mediaStateChanged(MediaPlayer arg0, int arg1) {
411
			//				System.out.println("mediaStateChanged: "+arg1);
412
			//			}
413
			//			
414
			//			@Override
415
			//			public void mediaParsedChanged(MediaPlayer arg0, int arg1) {
416
			//				System.out.println("mediaParsedChanged: "+arg1);
417
			//			}
418
			//			
419
			//			@Override
420
			//			public void mediaMetaChanged(MediaPlayer arg0, int arg1) {
421
			//				System.out.println("mediaMetaChanged: "+arg1);
422
			//			}
423
			//			
424
			//			@Override
425
			//			public void mediaFreed(MediaPlayer arg0) {
426
			//				System.out.println("mediaFreed: ");
427
			//			}
428
			//			
429
			//			@Override
430
			//			public void mediaDurationChanged(MediaPlayer arg0, long arg1) {
431
			//				//System.out.println("mediaDurationChanged: "+arg1);
432
			//			}
433
			//			
434
			//			@Override
435
			//			public void mediaChanged(MediaPlayer arg0, libvlc_media_t arg1, String arg2) {
436
			//				System.out.println("mediaChanged: "+arg1+" "+arg2);
437
			//			}
438
			//			
439
			
440 351
			@Override
441 352
			public void lengthChanged(MediaPlayer arg0, final long arg1) {
442 353
				if (firstLengthEvent) {
......
447 358
						@Override
448 359
						public void run() {
449 360
							timeRange.setMaximum((int)arg1);
450
							if (start == end) end = (int)arg1;
361
							//if (start == end) end = (int)arg1;
362
							
363
							
364
							if (end > 0 && start != end) {
365
								timeRange.setUpperValue(end);
366
							} else {
367
								timeRange.setUpperValue((int)arg1);
368
							}
369
							
451 370
							timeRange.setLowerValue(start);
452
							timeRange.setUpperValue(end);
453 371
							//System.out.println("Range: "+start+" -> "+end+" song length "+arg1);
454 372
						}
455 373
					});
456 374
				}
457 375
			}
458
			//			
459
			//			@Override
460
			//			public void forward(MediaPlayer arg0) {
461
			//				System.out.println("forward: ");
462
			//			}
463
			//			
464
			//			@Override
465
			//			public void finished(MediaPlayer arg0) {
466
			//				System.out.println("finished: ");
467
			//			}
468
			//			
469
			//			@Override
470
			//			public void error(MediaPlayer arg0) {
471
			//				System.out.println("error: ");
472
			//			}
473
			//			
474
			//			@Override
475
			//			public void endOfSubItems(MediaPlayer arg0) {
476
			//				System.out.println("endOfSubItems: ");
477
			//			}
478
			//			
479
			//			@Override
480
			//			public void buffering(MediaPlayer arg0, float arg1) {
481
			//				//System.out.println("buffering: "+arg1);
482
			//			}
483
			//			
484
			//			@Override
485
			//			public void backward(MediaPlayer arg0) {
486
			//				System.out.println("backward: ");
487
			//			}
488
			//
489
			//			@Override
490
			//			public void mediaSubItemAdded(MediaPlayer arg0, libvlc_media_t arg1) {
491
			//				// TODO Auto-generated method stub
492
			//				
493
			//			}
494 376
		});
495

  
496 377
	}
497 378

  
498 379
	private void updateTimeLabel() {
499 380
		mins = time / 60000;
500
		secs = time % 60000;
381
		secs = (time / 1000) % 60;
501 382
		timeLabel.setText(String.format("%02d:%02d", mins, secs)); //$NON-NLS-1$
502 383
		timeLabel.update();
503 384
	}
......
550 431
	}
551 432

  
552 433
	public void hideStopButton() {
553
		if (this.stopButton != null && !this.stopButton.isDisposed())
434
		if (this.stopButton != null && !this.stopButton.isDisposed()) {
554 435
			this.stopButton.dispose();
436
		}
555 437
	}
556 438

  
557 439
	DateTimeFormatter hhmmssFormatter = DateTimeFormatter.ISO_LOCAL_TIME;
......
566 448
		if (startTime.matches("[0-9]+.[0-9]+")) {
567 449
			start = (int)(1000*Float.parseFloat(startTime));
568 450
		} else if (startTime.matches("[0-9]+:[0-9]+:[0-9]+")) {
569
			if (startTime.indexOf(":") == 1) startTime = "0"+startTime;
451
			if (startTime.indexOf(":") == 1) {
452
				startTime = "0"+startTime;
453
			}
570 454
			LocalTime time1 = LocalTime.parse(startTime, hhmmssFormatter);
571
			start = (time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond();
455
			start = 1000*((time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond());
572 456
		}
573 457
		
574 458
		if (endTime.matches("[0-9]+.[0-9]+")) {
......
576 460
		} else if (endTime.matches("[0-9]+:[0-9]+:[0-9]+")) {
577 461
			if (endTime.indexOf(":") == 1) endTime = "0"+endTime;
578 462
			LocalTime time1 = LocalTime.parse(endTime, hhmmssFormatter);
579
			end = (time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond();
463
			end = 1000*((time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond());
580 464
		}
581 465
		
466
		//if (start == end) end = -1;
467
		
582 468
		Log.fine(MessagesMP.bind(MessagesMP.playing, new Object[]{mrl, startTime, endTime}));
583 469
		vlcPlayer.playMedia(mrl);
584 470
		vlcPlayer.setTime(start);
......
600 486
	public void stop() {
601 487
		vlcPlayer.stop();
602 488
		currentlyPlayed = NOMEDIA;
603
		if (!playButton.isDisposed()) playButton.setText(MessagesMP.play);
489
		if (!playButton.isDisposed()) {
490
			playButton.setText(MessagesMP.play);
491
		}
604 492
	}
605 493
}

Also available in: Unified diff