@viewlift/player-backup 1.0.2 → 1.0.3-lighteningjs
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +8 -0
- package/.browserslistrc +2 -0
- package/README.md +29 -0
- package/babel.config.json +8 -0
- package/dist/38afc79c94e0bcf0.png +0 -0
- package/dist/3bc8b7ff04e98d37.png +0 -0
- package/dist/522ea7c76ac4fd33.png +0 -0
- package/dist/a74cd46ed4277568.png +0 -0
- package/dist/b739faec1fde1346.png +0 -0
- package/dist/ed3d0a4d9de91460.png +0 -0
- package/dist/index.cjs.css +2 -0
- package/dist/index.cjs.css.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.esm.css +2 -0
- package/dist/index.esm.css.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/main-player/player-ui.d.ts +19 -0
- package/dist/player-components/player-buttons/playerButtons.d.ts +38 -0
- package/dist/player-components/player-seekbar/playerSeekbar.d.ts +25 -0
- package/dist/player-ui/player-ui.d.ts +18 -0
- package/dist/playerInitializer.d.ts +13 -0
- package/index.html +49 -0
- package/package.json +35 -15
- package/rollup.config.mjs +45 -0
- package/src/ads-manager/ads-manager.js +120 -0
- package/src/assets/checkIcon.png +0 -0
- package/src/assets/pauseIcon.png +0 -0
- package/src/assets/pauseIconFocus.png +0 -0
- package/src/assets/playIcon.png +0 -0
- package/src/assets/playIconFocus.png +0 -0
- package/src/assets/settingsIcon.png +0 -0
- package/src/index.ts +74 -0
- package/src/player-components/player-buttons/playerButtons.js +106 -0
- package/src/player-components/player-seekbar/playerSeekbar.js +223 -0
- package/src/player-components/player-setting-option-wrapper/player-setting-option-one-wrapper.js +82 -0
- package/src/player-components/player-setting-option-wrapper/player-setting-option-two-wrapper.js +84 -0
- package/src/player-components/player-sidebar/player-sidebar.js +188 -0
- package/src/player-components/player-title/playerTitle.js +56 -0
- package/src/player-ui/player-ui.js +564 -0
- package/src/playerControls/playerControls.css +10 -0
- package/src/playerControls/playerControls.js +501 -0
- package/src/playerInitializer.js +335 -0
- package/src/styles/index.css +204 -0
- package/src/utilities/utilities.js +79 -0
- package/tsconfig.json +15 -0
- package/cjs/autoNextVideo-815419cb.js +0 -1
- package/cjs/bundle.css +0 -577
- package/cjs/caption-settings-67212c17.js +0 -1
- package/cjs/caption-settings-6e301004.js +0 -1
- package/cjs/dvr_skin-f7f770ae.js +0 -1
- package/cjs/error-26d5a3c3.js +0 -1
- package/cjs/features-fd1e9785.js +0 -1
- package/cjs/generic-81b1be69.js +0 -1
- package/cjs/icons-51594f89.js +0 -1
- package/cjs/index.js +0 -1
- package/cjs/keyboardShortcuts-1afbf18c.js +0 -1
- package/cjs/loader-393b838a.js +0 -1
- package/cjs/multicam-1647c428.js +0 -1
- package/cjs/multicam-a41fe4a6.js +0 -1
- package/cjs/multicamv2-76d8530b.js +0 -1
- package/cjs/multicamv2-f48d95fe.js +0 -1
- package/cjs/mwebPotrait-3c11d7cf.js +0 -1
- package/cjs/mwebPotraitTray-a3a2715b.js +0 -1
- package/cjs/nextEpisodeButton-b6e6586f.js +0 -1
- package/cjs/nextEpisodeButton-cc80609a.js +0 -1
- package/cjs/nondvr_skin-ef2cb3b2.js +0 -1
- package/cjs/playlist-a550a735.js +0 -1
- package/cjs/playlist-df87ca90.js +0 -1
- package/cjs/renditions-c3ea26e8.js +0 -1
- package/cjs/resolution-51b38a3e.js +0 -1
- package/cjs/series-6178964e.js +0 -1
- package/cjs/series-9c237975.js +0 -1
- package/cjs/series-v2-70137d8c.js +0 -1
- package/cjs/series-v2-a265ff17.js +0 -1
- package/cjs/settings-icon-b350b587.js +0 -1
- package/cjs/settings-icon-e6a8feee.js +0 -1
- package/cjs/skin-14da56f6.js +0 -1
- package/cjs/skin-225252ff.js +0 -1
- package/cjs/skin-286f52db.js +0 -1
- package/cjs/skin-534810ae.js +0 -1
- package/cjs/skin-638aecc2.js +0 -1
- package/cjs/skin-84083352.js +0 -1
- package/cjs/skin-983a2ea7.js +0 -1
- package/cjs/skin-9eba464b.js +0 -1
- package/cjs/skin-b703ef26.js +0 -1
- package/cjs/skin-f225a42e.js +0 -1
- package/cjs/util-ce8a4138.js +0 -1
- package/cjs/videoSelector-a4c00f50.js +0 -1
- package/cjs/videoSelector-fcdf11eb.js +0 -1
- package/esm/autoNextVideo-89ede579.js +0 -1
- package/esm/bundle.css +0 -577
- package/esm/caption-settings-2e47813b.js +0 -1
- package/esm/caption-settings-3f6b6163.js +0 -1
- package/esm/dvr_skin-9cc1b144.js +0 -1
- package/esm/error-2395864b.js +0 -1
- package/esm/features-05101ce6.js +0 -1
- package/esm/generic-4a3c0d6b.js +0 -1
- package/esm/icons-f5378bf3.js +0 -1
- package/esm/index.js +0 -1
- package/esm/keyboardShortcuts-7fa108ec.js +0 -1
- package/esm/loader-580278fe.js +0 -1
- package/esm/multicam-bc0aea8a.js +0 -1
- package/esm/multicam-de741974.js +0 -1
- package/esm/multicamv2-d006cffa.js +0 -1
- package/esm/multicamv2-fb91fa98.js +0 -1
- package/esm/mwebPotrait-3c1805d8.js +0 -1
- package/esm/mwebPotraitTray-0ff12233.js +0 -1
- package/esm/nextEpisodeButton-a1556cdf.js +0 -1
- package/esm/nextEpisodeButton-ec95417f.js +0 -1
- package/esm/nondvr_skin-64be70e5.js +0 -1
- package/esm/playlist-5d3f4436.js +0 -1
- package/esm/playlist-7ecf432a.js +0 -1
- package/esm/renditions-0fdb57ed.js +0 -1
- package/esm/resolution-57e7767a.js +0 -1
- package/esm/series-041152aa.js +0 -1
- package/esm/series-998e2084.js +0 -1
- package/esm/series-v2-0727ee8c.js +0 -1
- package/esm/series-v2-9bcd5d54.js +0 -1
- package/esm/settings-icon-0125bffd.js +0 -1
- package/esm/settings-icon-9bac9ef3.js +0 -1
- package/esm/skin-0aea7a56.js +0 -1
- package/esm/skin-2c638dc1.js +0 -1
- package/esm/skin-5a02ebe6.js +0 -1
- package/esm/skin-665ec17e.js +0 -1
- package/esm/skin-80957fd8.js +0 -1
- package/esm/skin-851ea2fb.js +0 -1
- package/esm/skin-bb73c15b.js +0 -1
- package/esm/skin-cd537931.js +0 -1
- package/esm/skin-d5510f70.js +0 -1
- package/esm/skin-fba79111.js +0 -1
- package/esm/util-9c9ee6b3.js +0 -1
- package/esm/videoSelector-8da87dd3.js +0 -1
- package/esm/videoSelector-8e258d45.js +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"name": "@viewlift/player-backup",
|
|
3
|
+
"version": "1.0.3-lighteningjs",
|
|
4
|
+
"description": "A LightningJS video player component for Smart TV apps.",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rollup -c",
|
|
10
|
+
"dev": "rollup -c -w",
|
|
11
|
+
"test": "echo \"No tests specified\" && exit 0"
|
|
12
|
+
},
|
|
13
|
+
"author": "ViewLift",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"LightningJS",
|
|
17
|
+
"SmartTV",
|
|
18
|
+
"video-player"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/core": "^7.24.4",
|
|
22
|
+
"@babel/preset-env": "^7.24.4",
|
|
23
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
24
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
26
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
27
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
28
|
+
"@rollup/plugin-url": "^8.0.2",
|
|
29
|
+
"rollup": "^4.16.4",
|
|
30
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
31
|
+
"tslib": "^2.6.2",
|
|
32
|
+
"typescript": "^5.4.5"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@viewlift/player-backup": "^2.0.37-smarttv"
|
|
36
|
+
}
|
|
17
37
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import terser from '@rollup/plugin-terser';
|
|
4
|
+
import typescript from '@rollup/plugin-typescript';
|
|
5
|
+
import babel from '@rollup/plugin-babel';
|
|
6
|
+
import postcss from 'rollup-plugin-postcss';
|
|
7
|
+
import url from '@rollup/plugin-url';
|
|
8
|
+
|
|
9
|
+
const devMode = 'development';
|
|
10
|
+
export default {
|
|
11
|
+
input: 'src/playerInitializer.js',
|
|
12
|
+
output: [
|
|
13
|
+
{
|
|
14
|
+
file: 'dist/index.cjs.js',
|
|
15
|
+
format: 'cjs',
|
|
16
|
+
exports: 'auto',
|
|
17
|
+
sourcemap: devMode ? 'inline' : false
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
file: 'dist/index.esm.js',
|
|
21
|
+
format: 'esm',
|
|
22
|
+
sourcemap: devMode ? 'inline' : false
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
plugins: [
|
|
26
|
+
resolve(),
|
|
27
|
+
commonjs(),
|
|
28
|
+
typescript({ tsconfig: './tsconfig.json' }),
|
|
29
|
+
babel({
|
|
30
|
+
babelHelpers: 'bundled',
|
|
31
|
+
extensions: ['.js', '.ts'],
|
|
32
|
+
exclude: 'node_modules/**',
|
|
33
|
+
}),
|
|
34
|
+
postcss({
|
|
35
|
+
extract: true, // creates a separate CSS file
|
|
36
|
+
minimize: true,
|
|
37
|
+
sourceMap: true,
|
|
38
|
+
}),
|
|
39
|
+
url({
|
|
40
|
+
include: ['**/*.png', '**/*.jpg', '**/*.gif'],
|
|
41
|
+
limit: 0, // Always copy the files
|
|
42
|
+
}),
|
|
43
|
+
terser(),
|
|
44
|
+
],
|
|
45
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Button } from "../player-components/player-buttons/playerButtons";
|
|
2
|
+
|
|
3
|
+
export class AdsManager {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
this.adsMediaPlaybackList = props.adsMediaPlaybackList;
|
|
6
|
+
this.isSkipAble = props.isSkipAble;
|
|
7
|
+
this.playerResumeCallback = props.playerResumeCallback;
|
|
8
|
+
this.adsPlayerId = props.adsPlayerId;
|
|
9
|
+
|
|
10
|
+
this.initializeAdsPlayer();
|
|
11
|
+
this.addAdsEventListener();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
initializeAdsPlayer() {
|
|
15
|
+
this.adsContainer = document.createElement("div");
|
|
16
|
+
this.adsContainer.className = "adsContainer";
|
|
17
|
+
this.video = document.createElement('video');
|
|
18
|
+
this.adsContainer.appendChild(this.video);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
addAdsEventListener() {
|
|
22
|
+
this.video.addEventListener("ended", onEnded);
|
|
23
|
+
this.video.addEventListener("error", onError);
|
|
24
|
+
this.video.addEventListener("waiting", onBuffering);
|
|
25
|
+
this.video.addEventListener("play", onPlay);
|
|
26
|
+
this.video.addEventListener("playing", onPlaying);
|
|
27
|
+
this.video.addEventListener("timeupdate", playbackprogress);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
removeAdsEventListener() {
|
|
31
|
+
this.video.removeEventListener("ended", onEnded);
|
|
32
|
+
this.video.removeEventListener("error", onError);
|
|
33
|
+
this.video.removeEventListener("waiting", onBuffering);
|
|
34
|
+
this.video.removeEventListener("play", onPlay);
|
|
35
|
+
this.video.removeEventListener("playing", onPlaying);
|
|
36
|
+
this.video.removeEventListener("timeupdate", playbackprogress);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onEnded() {
|
|
40
|
+
console.log("AdsManager: ended");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onError() {
|
|
44
|
+
console.log("AdsManager: error");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onBuffering() {
|
|
48
|
+
console.log("AdsManager: buffering");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onPlay() {
|
|
52
|
+
console.log("AdsManager: play");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onPlaying() {
|
|
56
|
+
console.log("AdsManager: playing");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
playbackprogress() {
|
|
60
|
+
console.log("AdsManager: playback progress");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
createPlayPauseBtn() {
|
|
65
|
+
this.playPauseBtn = new Button({
|
|
66
|
+
imgSrc: playIconFocus,
|
|
67
|
+
imgAltText: 'Play/Pause',
|
|
68
|
+
buttonText: 'Play',
|
|
69
|
+
width: 70,
|
|
70
|
+
height: 70,
|
|
71
|
+
klassname: 'play-pause-btn',
|
|
72
|
+
focused: false,
|
|
73
|
+
disabled: false,
|
|
74
|
+
handleClick: () => {
|
|
75
|
+
if (this.video.paused) {
|
|
76
|
+
this.video.play();
|
|
77
|
+
if (this.playPauseBtn && this.playPauseBtn.buttonElement && this.playPauseBtn.buttonElement.querySelector('img')) {
|
|
78
|
+
this.playPauseBtn.buttonElement.querySelector('img').setAttribute('src', pauseIconFocus);
|
|
79
|
+
} else if (this.playPauseBtn && this.playPauseBtn.buttonElement) {
|
|
80
|
+
this.playPauseBtn.buttonElement.textContent = 'Pause';
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
this.video.pause();
|
|
84
|
+
if (this.playPauseBtn && this.playPauseBtn.buttonElement) {
|
|
85
|
+
this.playPauseBtn.buttonElement.querySelector('img').setAttribute('src', playIconFocus);
|
|
86
|
+
} else if (this.playPauseBtn && this.playPauseBtn.buttonElement) {
|
|
87
|
+
this.playPauseBtn.buttonElement.textContent = 'Play';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
this.playPauseBtn.mount(this.adsContainer);
|
|
93
|
+
|
|
94
|
+
requestAnimationFrame(() => {
|
|
95
|
+
if (this.playPauseBtn) this.playPauseBtn.focus();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
this.playPauseBtnEventListeners();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
playPauseBtnEventListeners() {
|
|
102
|
+
if (!this.playPauseBtn || !this.playPauseBtn.buttonElement) return;
|
|
103
|
+
|
|
104
|
+
this.playPauseBtn.buttonElement.addEventListener('focus', () => {
|
|
105
|
+
if (this.playPauseBtn && this.playPauseBtn.buttonElement && this.playPauseBtn.buttonElement.querySelector('img')) {
|
|
106
|
+
const iconSrc = this.video.paused ? playIconFocus : pauseIconFocus;
|
|
107
|
+
this.playPauseBtn.buttonElement.querySelector('img').setAttribute('src', iconSrc);
|
|
108
|
+
this.playPauseBtn.buttonElement.style.backgroundColor = 'rgba(255, 255, 255)';
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.playPauseBtn.buttonElement.addEventListener('blur', () => {
|
|
113
|
+
if (this.playPauseBtn && this.playPauseBtn.buttonElement && this.playPauseBtn.buttonElement.querySelector('img')) {
|
|
114
|
+
const iconSrc = this.video.paused ? playIcon : pauseIcon;
|
|
115
|
+
this.playPauseBtn.buttonElement.querySelector('img').setAttribute('src', iconSrc);
|
|
116
|
+
this.playPauseBtn.buttonElement.style.backgroundColor = 'rgba(255, 255, 255, 0.5)';
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// LightningJS-compatible Video Player Component (ES5 compatible)
|
|
2
|
+
import VLPlayerCore from '@viewlift/player-backup/esm';
|
|
3
|
+
import '@viewlift/player-backup/esm/bundle.css';
|
|
4
|
+
import PlayerControls from './playerControls/playerControls.js';
|
|
5
|
+
import "./styles/index.css";
|
|
6
|
+
export interface VideoPlayerOptions {
|
|
7
|
+
// Optional playback callbacks
|
|
8
|
+
onPlaybackSuccess?: (result: object) => void;
|
|
9
|
+
onPlaybackEnded?: () => void;
|
|
10
|
+
onPlaybackError?: (error?: object) => void;
|
|
11
|
+
playerId: string;
|
|
12
|
+
autoplay?: boolean;
|
|
13
|
+
controls?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
// Event callbacks
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class VideoPlayer {
|
|
20
|
+
/**
|
|
21
|
+
* Reinitialize the current videoElement with a new set of options and handle autoplay.
|
|
22
|
+
*/
|
|
23
|
+
reinitialize(options: VideoPlayerOptions,container: HTMLElement) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
//this.videoElement.src = options.src;
|
|
26
|
+
this.videoElement.autoplay = !!options.autoplay;
|
|
27
|
+
this.videoElement.controls = !!options.controls;
|
|
28
|
+
if (options.width) {
|
|
29
|
+
this.videoElement.width = options.width;
|
|
30
|
+
} else {
|
|
31
|
+
this.videoElement.removeAttribute('width');
|
|
32
|
+
}
|
|
33
|
+
if (options.height) {
|
|
34
|
+
this.videoElement.height = options.height;
|
|
35
|
+
} else {
|
|
36
|
+
this.videoElement.removeAttribute('height');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
private videoElement: HTMLVideoElement;
|
|
40
|
+
private options: VideoPlayerOptions;
|
|
41
|
+
private playerContainer: HTMLElement;
|
|
42
|
+
|
|
43
|
+
constructor(options: VideoPlayerOptions, container: HTMLElement) {
|
|
44
|
+
this.options = options;
|
|
45
|
+
this.playerContainer = container;
|
|
46
|
+
this.videoElement = document.createElement('video');
|
|
47
|
+
this.videoElement.id = options.playerId;
|
|
48
|
+
this.videoElement.autoplay = !!options.autoplay;
|
|
49
|
+
this.videoElement.controls = !!options.controls;
|
|
50
|
+
if (options.width) this.videoElement.width = options.width;
|
|
51
|
+
if (options.height) this.videoElement.height = options.height;
|
|
52
|
+
this.videoElement.style.display = 'block';
|
|
53
|
+
this.videoElement.style.background = 'black';
|
|
54
|
+
this.playerContainer.appendChild(this.videoElement);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
initialize() {
|
|
59
|
+
return VLPlayerCore().init(this.options).then((result:object)=>{
|
|
60
|
+
this.configureWebSDKPlayer(result);
|
|
61
|
+
return result;
|
|
62
|
+
}).catch((error:object) => {
|
|
63
|
+
return error
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
configureWebSDKPlayer(result: object){
|
|
67
|
+
VLPlayerCore().onVideoEnded(this.options.playerId,this.options.onPlaybackEnded);
|
|
68
|
+
let playerUi = new PlayerControls(result);
|
|
69
|
+
playerUi.attachTo(this.playerContainer);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export class Button {
|
|
2
|
+
constructor(props) {
|
|
3
|
+
if (!props) {
|
|
4
|
+
throw new Error('Button Class: props are required');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
this.imgSrc = props.imgSrc || '';
|
|
8
|
+
this.imgAltText = props.imgAltText || '';
|
|
9
|
+
this.buttonText = props.buttonText || '';
|
|
10
|
+
this.klassname = props.klassname || 'default-button';
|
|
11
|
+
this.width = props.width;
|
|
12
|
+
this.height = props.height;
|
|
13
|
+
this.fontWeight = props.fontWeight;
|
|
14
|
+
this.focused = props.focused || false;
|
|
15
|
+
this.disabled = props.disabled || false;
|
|
16
|
+
this.handleClick = props.handleClick || (() => {});
|
|
17
|
+
|
|
18
|
+
if (typeof this.handleClick !== 'function') {
|
|
19
|
+
throw new Error('Button Class: handleClick must be a function');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (this.disabled) {
|
|
23
|
+
this.klassname += ' disabled';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (this.focused) {
|
|
27
|
+
this.klassname += ' focused';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.handleClick = this.handleClick.bind(this);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
focus() {
|
|
34
|
+
if (this.buttonElement) {
|
|
35
|
+
this.buttonElement.focus();
|
|
36
|
+
this.buttonElement.classList.add('focused');
|
|
37
|
+
this.focused = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
blur() {
|
|
42
|
+
if (this.buttonElement) {
|
|
43
|
+
this.buttonElement.blur();
|
|
44
|
+
this.buttonElement.classList.remove('focused');
|
|
45
|
+
this.focused = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
mount(mountPoint) {
|
|
50
|
+
if (!mountPoint || !(mountPoint instanceof HTMLElement)) {
|
|
51
|
+
throw new Error('Button Class: mountPoint must be a valid DOM element');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const button = document.createElement('div');
|
|
55
|
+
button.className = this.klassname;
|
|
56
|
+
button.style.width = `${this.width}px`;
|
|
57
|
+
button.style.height = `${this.height}px`;
|
|
58
|
+
button.style.fontWeight = this.fontWeight;
|
|
59
|
+
button.tabIndex = 0;
|
|
60
|
+
|
|
61
|
+
if (this.imgSrc) {
|
|
62
|
+
const img = document.createElement('img');
|
|
63
|
+
img.src = this.imgSrc;
|
|
64
|
+
img.alt = this.imgAltText;
|
|
65
|
+
img.onerror = () => {
|
|
66
|
+
console.warn('Button Class: Failed to load image at', this.imgSrc);
|
|
67
|
+
};
|
|
68
|
+
button.appendChild(img);
|
|
69
|
+
} else {
|
|
70
|
+
const span = document.createElement('span');
|
|
71
|
+
span.textContent = this.buttonText;
|
|
72
|
+
button.appendChild(span);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!this.disabled) {
|
|
76
|
+
button.addEventListener('click', this.handleClick);
|
|
77
|
+
}
|
|
78
|
+
button.addEventListener('keydown', (event) => {
|
|
79
|
+
if (event.key === 'Enter' || event.key === 'OK') {
|
|
80
|
+
this.handleClick();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
button.addEventListener('focus', () => {
|
|
84
|
+
this.focused = true;
|
|
85
|
+
button.classList.add('focused');
|
|
86
|
+
});
|
|
87
|
+
button.addEventListener('blur', () => {
|
|
88
|
+
this.focused = false;
|
|
89
|
+
button.classList.remove('focused');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
this.buttonElement = button;
|
|
93
|
+
mountPoint.appendChild(button);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
unmount() {
|
|
97
|
+
if (this.buttonElement) {
|
|
98
|
+
this.buttonElement.removeEventListener('click', this.handleClick);
|
|
99
|
+
this.buttonElement.removeEventListener('keydown', this.handleClick);
|
|
100
|
+
this.buttonElement.removeEventListener('focus', this.handleClick);
|
|
101
|
+
this.buttonElement.removeEventListener('blur', this.handleClick);
|
|
102
|
+
this.buttonElement.remove();
|
|
103
|
+
this.buttonElement = undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
export class PlayerSeekbar {
|
|
2
|
+
constructor(video) {
|
|
3
|
+
if (!video || !(video instanceof HTMLVideoElement)) {
|
|
4
|
+
throw new Error('PlayerSeekbar: A valid HTMLVideoElement is required');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
this.video = video;
|
|
8
|
+
this.container = null;
|
|
9
|
+
this.progress = null;
|
|
10
|
+
this.buffer = null;
|
|
11
|
+
this.thumb = null;
|
|
12
|
+
this.tooltip = null;
|
|
13
|
+
this.timeLabel = null;
|
|
14
|
+
this.durationLabel = null;
|
|
15
|
+
this.isDragging = false;
|
|
16
|
+
this.focused = false;
|
|
17
|
+
|
|
18
|
+
this.init();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
init() {
|
|
22
|
+
this.container = document.createElement('div');
|
|
23
|
+
this.container.className = 'seekbar-container';
|
|
24
|
+
|
|
25
|
+
this.buffer = document.createElement('div');
|
|
26
|
+
this.buffer.className = 'seekbar-buffer';
|
|
27
|
+
|
|
28
|
+
this.progress = document.createElement('div');
|
|
29
|
+
this.progress.className = 'seekbar-progress';
|
|
30
|
+
|
|
31
|
+
this.thumb = document.createElement('div');
|
|
32
|
+
this.thumb.className = 'seekbar-thumb';
|
|
33
|
+
this.thumb.tabIndex = 0; // Make thumb focusable
|
|
34
|
+
|
|
35
|
+
this.tooltip = document.createElement('div');
|
|
36
|
+
this.tooltip.className = 'seekbar-tooltip';
|
|
37
|
+
this.tooltip.style.display = 'none';
|
|
38
|
+
|
|
39
|
+
this.timeLabel = document.createElement('span');
|
|
40
|
+
this.timeLabel.className = 'seekbar-time-label';
|
|
41
|
+
this.durationLabel = document.createElement('span');
|
|
42
|
+
this.durationLabel.className = 'seekbar-duration-label';
|
|
43
|
+
|
|
44
|
+
this.container.appendChild(this.buffer);
|
|
45
|
+
this.container.appendChild(this.progress);
|
|
46
|
+
this.container.appendChild(this.thumb);
|
|
47
|
+
this.container.appendChild(this.tooltip);
|
|
48
|
+
this.container.appendChild(this.timeLabel);
|
|
49
|
+
this.container.appendChild(this.durationLabel);
|
|
50
|
+
|
|
51
|
+
// Update UI as video plays
|
|
52
|
+
this.video.addEventListener('timeupdate', () => this.update());
|
|
53
|
+
this.video.addEventListener('progress', () => this.updateBuffer());
|
|
54
|
+
this.video.addEventListener('durationchange', () => this.update());
|
|
55
|
+
|
|
56
|
+
// Seek on click
|
|
57
|
+
this.container.addEventListener('click', (e) => this.seek(e));
|
|
58
|
+
// Dragging
|
|
59
|
+
this.thumb.addEventListener('mousedown', (e) => this.startDrag(e));
|
|
60
|
+
// Tooltip on hover
|
|
61
|
+
this.container.addEventListener('mousemove', (e) => this.showTooltip(e));
|
|
62
|
+
this.container.addEventListener('mouseleave', () => this.hideTooltip());
|
|
63
|
+
|
|
64
|
+
// Focus/blur events for accessibility and visual feedback
|
|
65
|
+
this.thumb.addEventListener('focus', () => {
|
|
66
|
+
this.focused = true;
|
|
67
|
+
this.thumb.classList.add('focused');
|
|
68
|
+
});
|
|
69
|
+
this.thumb.addEventListener('blur', () => {
|
|
70
|
+
this.focused = false;
|
|
71
|
+
this.thumb.classList.remove('focused');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Add keydown event listeners for arrow keys to simulate dragging
|
|
75
|
+
this.thumb.addEventListener('keydown', (e) => {
|
|
76
|
+
const increment = 1;
|
|
77
|
+
if (e.key === 'ArrowRight') {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
this.video.currentTime = Math.min(this.video.duration, this.video.currentTime + increment);
|
|
81
|
+
this.update();
|
|
82
|
+
} else if (e.key === 'ArrowLeft') {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
this.video.currentTime = Math.max(0, this.video.currentTime - increment);
|
|
86
|
+
this.update();
|
|
87
|
+
} else if (e.key === 'Enter') {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
if(this.video.paused) {
|
|
91
|
+
this.video.play(); // Resume playing the video
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
focus() {
|
|
98
|
+
if (this.thumb) {
|
|
99
|
+
this.thumb.focus();
|
|
100
|
+
this.thumb.classList.add('focused');
|
|
101
|
+
this.focused = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
blur() {
|
|
106
|
+
if (this.thumb) {
|
|
107
|
+
this.thumb.blur();
|
|
108
|
+
this.thumb.classList.remove('focused');
|
|
109
|
+
this.focused = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
formatTime(seconds) {
|
|
114
|
+
if (isNaN(seconds)) return '0:00';
|
|
115
|
+
const m = Math.floor(seconds / 60);
|
|
116
|
+
const s = Math.floor(seconds % 60);
|
|
117
|
+
return `${m}:${String(s).padStart(2, '0')}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
update() {
|
|
121
|
+
if (!this.video || !this.progress || !this.thumb || !this.timeLabel || !this.durationLabel) return;
|
|
122
|
+
|
|
123
|
+
const percent = (this.video.currentTime / this.video.duration) * 100;
|
|
124
|
+
this.progress.style.width = percent + '%';
|
|
125
|
+
this.thumb.style.left = percent + '%';
|
|
126
|
+
this.timeLabel.textContent = this.formatTime(this.video.currentTime);
|
|
127
|
+
this.durationLabel.textContent = ' / ' + this.formatTime(this.video.duration);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
updateBuffer() {
|
|
131
|
+
if (!this.video || !this.buffer) return;
|
|
132
|
+
|
|
133
|
+
if (this.video.buffered.length) {
|
|
134
|
+
const end = this.video.buffered.end(this.video.buffered.length - 1);
|
|
135
|
+
const percent = (end / this.video.duration) * 100;
|
|
136
|
+
this.buffer.style.width = percent + '%';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
seek(e) {
|
|
141
|
+
if (this.isDragging || !this.container || !this.video) return;
|
|
142
|
+
|
|
143
|
+
const rect = this.container.getBoundingClientRect();
|
|
144
|
+
const percent = (e.clientX - rect.left) / rect.width;
|
|
145
|
+
this.video.currentTime = percent * this.video.duration;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
startDrag(e) {
|
|
149
|
+
if (!this.container || !this.video) return;
|
|
150
|
+
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
this.isDragging = true;
|
|
153
|
+
const onMove = (moveEvent) => {
|
|
154
|
+
const rect = this.container.getBoundingClientRect();
|
|
155
|
+
let percent = (moveEvent.clientX - rect.left) / rect.width;
|
|
156
|
+
percent = Math.max(0, Math.min(1, percent));
|
|
157
|
+
this.progress.style.width = percent * 100 + '%';
|
|
158
|
+
this.thumb.style.left = percent * 100 + '%';
|
|
159
|
+
this.timeLabel.textContent = this.formatTime(percent * this.video.duration);
|
|
160
|
+
};
|
|
161
|
+
const onUp = (upEvent) => {
|
|
162
|
+
const rect = this.container.getBoundingClientRect();
|
|
163
|
+
let percent = (upEvent.clientX - rect.left) / rect.width;
|
|
164
|
+
percent = Math.max(0, Math.min(1, percent));
|
|
165
|
+
this.video.currentTime = percent * this.video.duration;
|
|
166
|
+
this.isDragging = false;
|
|
167
|
+
document.removeEventListener('mousemove', onMove);
|
|
168
|
+
document.removeEventListener('mouseup', onUp);
|
|
169
|
+
};
|
|
170
|
+
document.addEventListener('mousemove', onMove);
|
|
171
|
+
document.addEventListener('mouseup', onUp);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
showTooltip(e) {
|
|
175
|
+
if (!this.container || !this.tooltip || !this.video) return;
|
|
176
|
+
|
|
177
|
+
const rect = this.container.getBoundingClientRect();
|
|
178
|
+
const percent = (e.clientX - rect.left) / rect.width;
|
|
179
|
+
const time = percent * this.video.duration;
|
|
180
|
+
this.tooltip.textContent = this.formatTime(time);
|
|
181
|
+
this.tooltip.style.display = 'block';
|
|
182
|
+
this.tooltip.style.left = `${percent * 100}%`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
hideTooltip() {
|
|
186
|
+
if (this.tooltip) {
|
|
187
|
+
this.tooltip.style.display = 'none';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
getElement() {
|
|
192
|
+
return this.thumb;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
mount(parent) {
|
|
196
|
+
if (!parent || !(parent instanceof HTMLElement)) {
|
|
197
|
+
throw new Error('PlayerSeekbar: parent must be a valid DOM element');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
parent.appendChild(this.container);
|
|
201
|
+
this.update();
|
|
202
|
+
this.updateBuffer();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
unmount() {
|
|
206
|
+
if (!this.video || !this.container || !this.thumb) return;
|
|
207
|
+
|
|
208
|
+
this.video.removeEventListener('timeupdate', this.update);
|
|
209
|
+
this.video.removeEventListener('progress', this.updateBuffer);
|
|
210
|
+
this.video.removeEventListener('durationchange', this.update);
|
|
211
|
+
this.container.removeEventListener('click', this.seek);
|
|
212
|
+
this.thumb.removeEventListener('mousedown', this.startDrag);
|
|
213
|
+
this.container.removeEventListener('mousemove', this.showTooltip);
|
|
214
|
+
this.container.removeEventListener('mouseleave', this.hideTooltip);
|
|
215
|
+
this.thumb.removeEventListener('focus', this.focus);
|
|
216
|
+
this.thumb.removeEventListener('blur', this.blur);
|
|
217
|
+
this.thumb.removeEventListener('keydown', this.keydownHandler);
|
|
218
|
+
|
|
219
|
+
if (this.container) {
|
|
220
|
+
this.container.remove();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|