Skip to content

Commit b6c2d76

Browse files
authored
[FEATURE] Player stop on endTime timecode of an active segment (kitodo#1740)
1 parent e834fdc commit b6c2d76

File tree

9 files changed

+141
-6
lines changed

9 files changed

+141
-6
lines changed

Resources/Private/JavaScript/DlfMediaPlayer/DlfMediaPlayer.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ export default class DlfMediaPlayer extends HTMLElement {
721721
});
722722
this.dispatchEvent(event);
723723
}
724+
725+
// Pauses playback when the video reaches the active segment’s end.
726+
this.stopActiveSegment();
724727
}
725728

726729
onTrackChange() {
@@ -758,6 +761,9 @@ export default class DlfMediaPlayer extends HTMLElement {
758761

759762
onPlay() {
760763
this.videoPausedOn = null;
764+
765+
// Deactivates the segment if playback passes its end time.
766+
this.deactivateActiveSegment();
761767
}
762768

763769
/**
@@ -1065,6 +1071,67 @@ export default class DlfMediaPlayer extends HTMLElement {
10651071
console.error('Error from Shaka player', error.code, error);
10661072
}
10671073
}
1074+
1075+
/**
1076+
* Returns the active segment if it exists and has a valid endTime.
1077+
*
1078+
* @private
1079+
* @typedef {import('./Markers.js').Segment & { endTime: number }} SegmentWithEnd
1080+
* @returns {SegmentWithEnd | null}
1081+
*/
1082+
getValidActiveSegment() {
1083+
const activeSegment = this.markers_.activeSegment;
1084+
if (activeSegment === null || typeof activeSegment.endTime !== 'number') {
1085+
return null;
1086+
}
1087+
return /** @type {SegmentWithEnd} */ (activeSegment);
1088+
}
1089+
1090+
/**
1091+
* Checks whether the active segment has reached or passed its end time and deactivates it.
1092+
*
1093+
* @private
1094+
* @returns {boolean}
1095+
*/
1096+
deactivateActiveSegment() {
1097+
const activeSegment = this.getValidActiveSegment();
1098+
if (!activeSegment) return false;
1099+
1100+
const eps = 0.05;
1101+
1102+
if (Math.abs(this.video.currentTime - activeSegment.endTime) <= eps || this.video.currentTime >= activeSegment.endTime) {
1103+
try {
1104+
this.markers_.deactivateSegment();
1105+
} catch (e) {
1106+
console.debug('Could not deactivate segment after seek', e);
1107+
}
1108+
}
1109+
1110+
return true;
1111+
}
1112+
1113+
/**
1114+
* Checks whether playback has reached the active segment’s end time and pauses the video.
1115+
*
1116+
* @private
1117+
* @returns {boolean}
1118+
*/
1119+
stopActiveSegment() {
1120+
const activeSegment = this.getValidActiveSegment();
1121+
if (!activeSegment) return false;
1122+
1123+
if (!this.video.paused && this.video.currentTime >= activeSegment.endTime) {
1124+
this.video.pause();
1125+
try {
1126+
this.video.currentTime = activeSegment.endTime;
1127+
} catch (e) {
1128+
console.debug('Could not set video.currentTime to segment end:', e);
1129+
}
1130+
return true;
1131+
}
1132+
1133+
return false;
1134+
}
10681135
}
10691136

10701137
customElements.define('dlf-media', DlfMediaPlayer);

Resources/Private/JavaScript/DlfMediaPlayer/Markers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ export default class Markers extends EventTarget {
182182
}
183183
}
184184

185+
/**
186+
* Deactivates the currently active segment
187+
*/
188+
deactivateSegment() {
189+
this.activateSegment(null);
190+
}
191+
185192
/**
186193
*
187194
* @param {string} id

Resources/Private/Less/DlfMediaPlayer.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// Colors
3939
@base-color: rgb(28, 28, 28);
4040
@light-color: lighten(@base-color, 50%);
41+
@accent-color: #167;
4142

4243
// Labels
4344
@label-padding: 2pt;

Resources/Private/Less/DlfMediaPlayer/ShakaFrontend.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
height: 3.5em;
109109
width: 100%;
110110

111-
background-color: rgba(79, 179, 199, 0.6);
111+
background-color: fade(@accent-color, 12%);
112112

113113
video {
114114
display: none;

Resources/Private/Less/SlubMediaPlayer/components/MarkerTable.less

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
line-height: normal;
1010
}
1111

12+
table tr::before {
13+
content: "";
14+
display: table-cell;
15+
width: 4px;
16+
}
17+
1218
th {
1319
border-bottom: 1px solid black;
1420
}
@@ -17,12 +23,23 @@
1723
padding: 0.1em 2em 0.1em 0;
1824
}
1925

20-
tbody tr:hover {
21-
background-color: #eee;
26+
tbody tr {
27+
transition: background-color 0.3s ease, color 0.3s ease;
28+
29+
&:hover {
30+
background-color: #eee;
31+
}
2232
}
2333

2434
tr.active-segment {
25-
color: darkcyan;
35+
@active-bg: fade(@accent-color, 12%);
36+
color: @accent-color;
37+
38+
.hover-darken-bg(@active-bg, 5%);
39+
40+
&::before {
41+
background-color: @accent-color;
42+
}
2643
}
2744

2845
.marker-id-col {
@@ -46,6 +63,9 @@
4663
.marker-start-col,
4764
.marker-end-col {
4865
cursor: pointer;
66+
&:hover {
67+
color: lighten(@accent-color, 8%);
68+
}
4969
}
5070

5171
.marker-buttons-col {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
@import "util.less";
12
@import "SlubMediaPlayer.less";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Mixin: automatically darken/lighten background/text on hover
2+
//
3+
// Usage Example:
4+
// .button {
5+
// .hover-darken-bg(#ddd, 10%);
6+
// .hover-lighten-color(#eee, 10%);
7+
// }
8+
9+
.hover-lighten-bg(@bg-color, @bg-amount) {
10+
background-color: @bg-color;
11+
12+
&:hover {
13+
background-color: lighten(@bg-color, @bg-amount);
14+
}
15+
}
16+
17+
.hover-darken-bg(@bg-color, @bg-amount) {
18+
background-color: @bg-color;
19+
20+
&:hover {
21+
background-color: darken(@bg-color, @bg-amount);
22+
}
23+
}
24+
25+
.hover-lighten-color(@text-color, @text-amount) {
26+
color: @text-color;
27+
28+
&:hover {
29+
color: lighten(@text-color, @text-amount);
30+
}
31+
}
32+
33+
.hover-darken-color(@text-color, @text-amount) {
34+
color: @text-color;
35+
36+
&:hover {
37+
color: darken(@text-color, @text-amount);
38+
}
39+
}

Resources/Public/Css/DlfMediaPlayerStyles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/Public/JavaScript/DlfMediaPlayer/DlfMediaPlayer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)