Skip to content

Commit 93c3d09

Browse files
committed
feat(playback): added the ability to select where to start playing videos from (start, mid, random)
re #33
1 parent 477d7c8 commit 93c3d09

6 files changed

Lines changed: 22 additions & 0 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ ENV PROGRESS_BAR_POSITION="bottom"
2727
ENV IGNORE_HIDDEN_PATHS="false"
2828
ENV SCROLL_DIRECTION="vertical"
2929
ENV USE_CUSTOM_SKIN="false"
30+
ENV VIDEO_START_POSITION="start"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Erin has all these features implemented :
3232
- Automatic clip naming based on file name
3333
- Simple and optional security using a master password
3434
- Support for Horizontal and Vertical scroll direction
35+
- Support for starting video playback from the start, middle, or random point in the video
3536
- Support for custom styling\*\*\*\*
3637
- Support for HTTP and HTTPS
3738
- Support for Docker / proxy deployment
@@ -121,6 +122,7 @@ To run Erin, you will need to set the following environment variables in a `.env
121122
| `IGNORE_HIDDEN_PATHS` | `boolean` | Whether all hidden files and directories (starting with a dot) should be ignored by Erin, and not loaded or scanned altogether | false |
122123
| `SCROLL_DIRECTION` | `string` | The scroll direction of your video feed. (Possible values : vertical, horizontal ) | vertical |
123124
| `USE_CUSTOM_SKIN` | `boolean` | Whether a custom skin should be loaded on startup. (Possible values : true, false) | false |
125+
| `VIDEO_START_POSITION` | `string` | Where videos start playing. (Possible values : start, middle, random) | start |
124126

125127
> **Tip :** To generate a secure hash for your instance, use the following command :
126128

docker/Caddyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
replace __IGNORE_HIDDEN_PATHS__ {$IGNORE_HIDDEN_PATHS}
2727
replace __USE_CUSTOM_SKIN__ {$USE_CUSTOM_SKIN}
2828
replace __SCROLL_DIRECTION__ "{$SCROLL_DIRECTION}"
29+
replace __VIDEO_START_POSITION__ "{$VIDEO_START_POSITION}"
2930
}
3031

3132
# Server configuration

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
window.AUTOPLAY_ENABLED = __AUTOPLAY_ENABLED__;
3030
window.PROGRESS_BAR_POSITION = "__PROGRESS_BAR_POSITION__";
3131
window.IGNORE_HIDDEN_PATHS = __IGNORE_HIDDEN_PATHS__;
32+
window.VIDEO_START_POSITION = "__VIDEO_START_POSITION__";
3233
</script>
3334
</head>
3435
<body>

sample.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ AUTOPLAY_ENABLED=true
77
IGNORE_HIDDEN_PATHS=true
88
SCROLL_DIRECTION="vertical"
99
USE_CUSTOM_SKIN=false
10+
VIDEO_START_POSITION="start"

src/components/VideoFeed/index.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ const VideoFeed = ({
6666
onFinishVideo();
6767
};
6868

69+
const startVideoAtSpecificPoint = (e) => {
70+
e.target.currentTime = window.VIDEO_START_POSITION === 'middle'
71+
? e.target.duration / 2
72+
: Math.random() * e.target.duration;
73+
}
74+
6975
// Hook - On mount - Set the current scroll
7076
useEffect(() => {
7177
if (jumpToEnd)
@@ -105,6 +111,12 @@ const VideoFeed = ({
105111
if (entry.isIntersecting) {
106112
visibleIndex = currentIndex;
107113
videoElement.play().catch((_) => {});
114+
115+
if ( window.VIDEO_START_POSITION !== 'start' ) {
116+
if ( videoElement.readyState >= 1 ) startVideoAtSpecificPoint({ target: videoElement });
117+
else videoElement.addEventListener('loadedmetadata', startVideoAtSpecificPoint, true);
118+
}
119+
108120
onFocusVideo(videos[currentIndex], currentIndex);
109121
videoElement.addEventListener("timeupdate", handleVideoTimeUpdate, true);
110122
videoElement.addEventListener("ended", replayVideo, true);
@@ -116,6 +128,10 @@ const VideoFeed = ({
116128
videoElement.pause();
117129
videoElement.removeEventListener("timeupdate", handleVideoTimeUpdate, true);
118130
videoElement.removeEventListener("ended", replayVideo, true);
131+
132+
if ( window.VIDEO_START_POSITION !== 'start' ) {
133+
videoElement.removeEventListener('loadedmetadata', startVideoAtSpecificPoint, true);
134+
}
119135
}
120136
});
121137

0 commit comments

Comments
 (0)