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

Read duration from either options or player property in progressbar #578

Merged
merged 2 commits into from
Jul 19, 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
3 changes: 1 addition & 2 deletions src/components/MediaPlayer/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const MediaPlayer = ({
};

React.useEffect(() => {
const hlsOptions = withCredentials ? { hls: { withCredentials: true } } : {}
const hlsOptions = withCredentials ? { hls: { withCredentials: true } } : {};
let videoJsOptions;
// Only build the full set of option for the first playable Canvas since
// these options are only used on the initia Video.js instance creation
Expand Down Expand Up @@ -360,7 +360,6 @@ const MediaPlayer = ({
// 'vjsYo', custom component
],
videoJSProgress: {
duration: canvasDuration,
srcIndex,
targets,
currentTime: currentTime || 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ class VideoJSProgress extends vjsComponent {
this.options.targets = this.player.targets?.length > 0
? this.player.targets
: this.options.targets;
this.options.duration = this.player.canvasDuration;
this.mount();
this.initProgressBar();
});
}

/** Build progress bar elements from the options */
initProgressBar() {
const { targets, duration, srcIndex } = this.options;
const { targets, srcIndex } = this.options;
const { start, end } = targets[srcIndex];
const duration = this.player.canvasDuration;
let startTime = start,
endTime = end;

const isMultiSourced = targets.length > 1 ? true : false;
let totalDuration = targets.reduce((acc, t) => acc + t.duration, 0);

let toPlay;
if (isMultiSourced) {
let totalDuration = targets.reduce((acc, t) => acc + t.duration, 0);
// Calculate the width of the playable range as a percentage of total
// Canvas duration
toPlay = Math.min(
Expand Down