| | import { utilitiesInstance } from "./Utilities.js"; |
| |
|
| | export function isElementVideo(element) { |
| | return element && element.tagName === 'VIDEO'; |
| | } |
| |
|
| | export async function toggleVideoPlayback(video) { |
| | if (!video.pause || !video.play || !('paused' in video)) { return; } |
| |
|
| | if (video.paused) { |
| | await video.play(); |
| | } else { |
| | video.pause(); |
| | } |
| | }; |
| |
|
| | export function toggleVideoMute(video) { |
| | if ('muted' in video) { |
| | video.muted = !video.muted; |
| | } |
| | } |
| |
|
| | export function setVideoVolume(video, percentage) { |
| | video.volume = utilitiesInstance.clamp(percentage / 100, 0.0, 1.0); |
| | } |
| |
|
| | export function toggleVideoFullscreen(video) { |
| | if (!document.fullscreenElement) { |
| | video.requestFullscreen(); |
| | } else { |
| | document.exitFullscreen(); |
| | } |
| | } |
| |
|
| | export function setVideoPlaybackRate(video, rate) { |
| | video.playbackRate = utilitiesInstance.clamp(rate, 0.05, 100.00); |
| | } |
| |
|
| | export function seekVideo(video, delta) { |
| | if (!video.duration || !video.currentTime) { return; } |
| |
|
| | const maxTime = video.duration; |
| | const currentTime = video.currentTime; |
| | const seekStep = utilitiesInstance.clamp(maxTime / 100, 1, 10); |
| |
|
| | let newTime = currentTime + (delta * seekStep); |
| | newTime = utilitiesInstance.clamp(newTime, 0, maxTime); |
| |
|
| | video.currentTime = newTime; |
| | }; |
| |
|
| | export function onScrollVideo(video, event, bInvertWheelSeek) { |
| | event.preventDefault(); |
| |
|
| | |
| | let scrollDelta = Math.sign(event.deltaY); |
| |
|
| | if (bInvertWheelSeek) { |
| | scrollDelta *= -1; |
| | } |
| |
|
| | seekVideo(video, scrollDelta); |
| | } |