Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use control-bar width to add padding to progress-bar on sides #715

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/MediaPlayer/VideoJS/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function VideoJSPlayer({
player.on('ready', function () {
console.log('Player ready');

setControlBar(player);

// Add this class in mobile/tablet devices to always show the control bar,
// since the inactivityTimeout is flaky in some browsers
if (IS_MOBILE || IS_IPAD) {
Expand Down Expand Up @@ -157,6 +159,9 @@ function VideoJSPlayer({
player.on('timeupdate', () => {
handleTimeUpdate();
});
player.on('resize', () => {
setControlBar(player);
});
player.on('ended', () => {
/**
* Checking against isReadyRef.current stops from delayed events being executed
Expand Down Expand Up @@ -222,6 +227,17 @@ function VideoJSPlayer({
playerLoadedMetadata(player);
};

/**
* Set control bar width to offset 12px from left/right edges of player.
* This is set on player.ready and player.resize events.
* @param {Object} player
*/
const setControlBar = (player) => {
const playerWidth = player.currentWidth();
const controlBarWidth = playerWidth - 24;
player.controlBar.width(`${controlBarWidth}px`);
};

/**
* Update player properties and data when player is reloaded with
* source change, i.e. Canvas change
Expand Down Expand Up @@ -352,6 +368,9 @@ function VideoJSPlayer({
player.one('loadedmetadata', () => {
console.log('Player loadedmetadata');

// Update control-bar width on player reload
setControlBar(player);

player.duration(canvasDuration);

isEndedRef.current ? player.currentTime(0) : player.currentTime(currentTimeRef.current);
Expand Down
30 changes: 27 additions & 3 deletions src/components/MediaPlayer/VideoJS/videojs-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,39 @@
height: 5em;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, .75), rgba(0, 0, 0, .75));
display: flex;
padding: 2em 1em 0 1em;
padding-top: 2em;
left: 1em;

// Set faded effect background before and after control bar
&::before {
content: '';
width: 1em;
height: 100%;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, .75), rgba(0, 0, 0, .75)),
linear-gradient(to left, transparent, rgba(0, 0, 0, 0));
position: absolute;
left: 0.215em;
top: 0em;
transform: translateX(-120%);
}
&::after {
content: '';
width: 1em;
height: 100%;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, .75), rgba(0, 0, 0, .75)),
linear-gradient(to left, transparent, rgba(0, 0, 0, 0));
position: absolute;
right: -2.215em;
top: 0em;
transform: translateX(-121%);
}
}

.vjs-theme-ramp .vjs-custom-progress-bar {
position: absolute;
width: 98.75% !important;
width: 100% !important;
top: 1.25em;
margin: 0;
left: 1em;
}

.vjs-theme-ramp .vjs-progress-control .vjs-progress-holder {
Expand Down
5 changes: 5 additions & 0 deletions src/services/ramp-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ export const useVideoJSPlayer = ({
break;
}
});

// Listen for resize events and trigger player.resize event
window.addEventListener('resize', () => {
player.trigger('resize');
});
};

/**
Expand Down