@@ -48,97 +48,30 @@ export interface VideoCellType {
48
48
templateUrl : './timeline.component.html' ,
49
49
styleUrls : [ './timeline.component.scss' ]
50
50
} )
51
- export class TimelineComponent implements OnInit , OnChanges {
51
+ export class NgxVideoTimelineComponent implements OnInit , OnChanges {
52
52
53
- // Canvas scale is adjusted according to outer height
54
- private _scale = 20 ;
55
- get scale ( ) : number {
56
- return ( this . canvasHeight / 4.55 ) ;
57
- }
58
53
59
54
// The height of the outer canvas
60
- private _canvasHeight = 50 ;
61
- get canvasHeight ( ) : number {
62
- return this . _canvasHeight ;
63
- }
55
+ @Input ( ) canvasHeight = 50 ;
64
56
65
- @Input ( )
66
- set canvasHeight ( value : number ) {
67
- this . _canvasHeight = value ;
68
- }
57
+ // Canvas scale is adjusted according to outer height
58
+ scale = this . canvasHeight / 4.55 ;
69
59
70
60
// Video playback time
71
- private _playTime = new Date ( ) . getTime ( ) ;
72
- get playTime ( ) : number | string | Date {
73
- return this . _playTime ;
74
- }
75
-
76
- @Input ( )
77
- set playTime ( value : number | string | Date ) {
78
- if ( value instanceof String ) {
79
- this . _playTime = new Date ( value ) . getTime ( ) ;
80
- } else if ( value instanceof Date ) {
81
- this . _playTime = value . getTime ( ) ;
82
- } else if ( typeof value === 'number' ) {
83
- this . _playTime = Number ( value ) ;
84
- }
85
- }
61
+ @Input ( ) playTime : number | string | Date ;
86
62
87
63
// The video plays at twice the speed
88
- private _speed = 1 ;
89
- get speed ( ) : number {
90
- return 1 / this . _speed * 1000 ;
91
- }
92
-
93
- @Input ( )
94
- set speed ( value : number ) {
95
- this . _speed = value ;
96
- }
64
+ @Input ( ) speed : number ;
97
65
98
66
// Video fast forward value
99
- private _forWardValue = 5 ;
100
- get forWardValue ( ) : number {
101
- return this . _forWardValue * 1000 ;
102
- }
103
-
104
- @Input ( )
105
- set forWardValue ( value : number ) {
106
- this . _forWardValue = value ;
107
- }
67
+ @Input ( ) forWardValue : number ;
108
68
109
69
// Start time limit: Timestamp
110
- private _startTimeThreshold = new Date ( ) . getTime ( ) - 1 * 12 * 3600 * 1000 ;
111
- get startTimeThreshold ( ) : number | string | Date {
112
- return this . _startTimeThreshold ;
113
- }
114
-
115
- @Input ( )
116
- set startTimeThreshold ( value : number | string | Date ) {
117
- if ( value instanceof String ) {
118
- this . _startTimeThreshold = new Date ( value ) . getTime ( ) ;
119
- } else if ( value instanceof Date ) {
120
- this . _startTimeThreshold = value . getTime ( ) ;
121
- } else if ( typeof value === 'number' ) {
122
- this . _startTimeThreshold = Number ( value ) ;
123
- }
124
- }
70
+ @Input ( ) startTimeThreshold : number | string | Date ;
125
71
126
72
// End time limit: Timestamp
127
- private _endTimeThreshold = new Date ( ) . getTime ( ) + 1 * 12 * 3600 * 1000 ;
128
- get endTimeThreshold ( ) : number | string | Date {
129
- return this . _endTimeThreshold ;
130
- }
73
+ @Input ( ) endTimeThreshold : number | string | Date ;
131
74
132
- @Input ( )
133
- set endTimeThreshold ( value : number | string | Date ) {
134
- if ( value instanceof String ) {
135
- this . _endTimeThreshold = new Date ( value ) . getTime ( ) ;
136
- } else if ( value instanceof Date ) {
137
- this . _endTimeThreshold = value . getTime ( ) ;
138
- } else if ( typeof value === 'number' ) {
139
- this . _endTimeThreshold = Number ( value ) ;
140
- }
141
- }
142
75
// relation to Css Start
143
76
144
77
// color of canvas border
@@ -262,6 +195,11 @@ export class TimelineComponent implements OnInit, OnChanges {
262
195
constructor ( ) {
263
196
// this.startTimeThreshold = new Date().getTime() - 1 * 0.5 * 3600 * 1000;
264
197
// this.endTimeThreshold = new Date().getTime() + 1 * 1 * 3600 * 1000;
198
+ this . forWardValue = 5000 ;
199
+ this . speed = 1000 ;
200
+ this . playTime = new Date ( ) . getTime ( ) ;
201
+ this . startTimeThreshold = new Date ( ) . getTime ( ) - 1 * 12 * 3600 * 1000 ;
202
+ this . endTimeThreshold = new Date ( ) . getTime ( ) + 1 * 12 * 3600 * 1000 ;
265
203
this . playClick = new EventEmitter < any > ( ) ;
266
204
this . mouseUp = new EventEmitter < any > ( ) ;
267
205
this . mouseDown = new EventEmitter < any > ( ) ;
@@ -486,7 +424,14 @@ export class TimelineComponent implements OnInit, OnChanges {
486
424
// this.drawPalyBar();
487
425
}
488
426
if ( changes . startTimeThreshold ) {
489
- this . startTimeThreshold = changes . startTimeThreshold . currentValue ;
427
+ const value = changes . startTimeThreshold . currentValue ;
428
+ if ( changes . startTimeThreshold . currentValue instanceof String ) {
429
+ this . startTimeThreshold = new Date ( value ) . getTime ( ) ;
430
+ } else if ( value instanceof Date ) {
431
+ this . startTimeThreshold = value . getTime ( ) ;
432
+ } else if ( typeof value === 'number' ) {
433
+ this . startTimeThreshold = Number ( value ) ;
434
+ }
490
435
491
436
this . hoursPerRuler = Math . ceil ( ( Number ( this . endTimeThreshold ) - Number ( this . startTimeThreshold ) ) / 1000 / 3600 ) < 24
492
437
? Math . ceil ( ( Number ( this . endTimeThreshold ) - Number ( this . startTimeThreshold ) ) / 1000 / 3600 )
@@ -496,14 +441,29 @@ export class TimelineComponent implements OnInit, OnChanges {
496
441
// this.init(this.startTimestamp, this.timecell, false);
497
442
}
498
443
if ( changes . endTimeThreshold ) {
499
- this . endTimeThreshold = changes . endTimeThreshold . currentValue ;
444
+ const value = changes . endTimeThreshold . currentValue ;
445
+ if ( changes . endTimeThreshold . currentValue instanceof String ) {
446
+ this . endTimeThreshold = new Date ( value ) . getTime ( ) ;
447
+ } else if ( value instanceof Date ) {
448
+ this . endTimeThreshold = value . getTime ( ) ;
449
+ } else if ( typeof value === 'number' ) {
450
+ this . endTimeThreshold = Number ( value ) ;
451
+ }
500
452
this . hoursPerRuler = Math . ceil ( ( Number ( this . endTimeThreshold ) - Number ( this . startTimeThreshold ) ) / 1000 / 3600 ) < 24
501
453
? Math . ceil ( ( Number ( this . endTimeThreshold ) - Number ( this . startTimeThreshold ) ) / 1000 / 3600 )
502
454
: 24 ;
503
455
504
456
}
505
457
if ( changes . playTime ) {
506
- this . playTime = changes . playTime . currentValue ;
458
+
459
+ const value = changes . playTime . currentValue ;
460
+ if ( changes . playTime . currentValue instanceof String ) {
461
+ this . playTime = new Date ( value ) . getTime ( ) ;
462
+ } else if ( value instanceof Date ) {
463
+ this . playTime = value . getTime ( ) ;
464
+ } else if ( typeof value === 'number' ) {
465
+ this . playTime = Number ( value ) ;
466
+ }
507
467
508
468
// use SetTimeOut Timer to make it asynchronous
509
469
setTimeout ( ( ) => {
@@ -513,12 +473,13 @@ export class TimelineComponent implements OnInit, OnChanges {
513
473
}
514
474
if ( changes . speed ) {
515
475
516
- this . speed = changes . speed . currentValue ;
476
+ this . speed = Number ( changes . speed . currentValue ) * 1000 ;
517
477
}
518
478
if ( changes . forWardValue ) {
519
479
520
- this . forWardValue = changes . forWardValue . currentValue ;
480
+ this . forWardValue = Number ( changes . forWardValue . currentValue ) * 1000 ;
521
481
}
482
+
522
483
if ( changes . isPlayClick ) {
523
484
if ( changes . isPlayClick . currentValue ) {
524
485
this . onPlayClick ( ) ;
0 commit comments