From 51d0e1c7b4a4340a691fbcf0f0b4378519c6d21f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 21 Nov 2020 23:19:04 +0100 Subject: [Glitch] Fix hardcoded frame rate for frame by frame video navigation in web UI Port f970e1fab6ca5d2334604b86d6e472e64510ea40 to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/features/video/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'app/javascript/flavours/glitch/features/video') diff --git a/app/javascript/flavours/glitch/features/video/index.js b/app/javascript/flavours/glitch/features/video/index.js index ea40b6073..7e8996af4 100644 --- a/app/javascript/flavours/glitch/features/video/index.js +++ b/app/javascript/flavours/glitch/features/video/index.js @@ -98,6 +98,7 @@ class Video extends React.PureComponent { static propTypes = { preview: PropTypes.string, + frameRate: PropTypes.string, src: PropTypes.string.isRequired, alt: PropTypes.string, width: PropTypes.number, @@ -125,6 +126,10 @@ class Video extends React.PureComponent { muted: PropTypes.bool, }; + static defaultProps = { + frameRate: 25, + }; + state = { currentTime: 0, duration: 0, @@ -298,7 +303,7 @@ class Video extends React.PureComponent { } handleKeyDown = e => { - const frameTime = 1 / 25; + const frameTime = 1 / this.getFrameRate(); switch(e.key) { case 'k': @@ -531,6 +536,17 @@ class Video extends React.PureComponent { this.props.onCloseVideo(); } + getFrameRate () { + if (this.props.frameRate && isNaN(this.props.frameRate)) { + // The frame rate is returned as a fraction string so we + // need to convert it to a number + + return this.props.frameRate.split('/').reduce((p, c) => p / c); + } + + return this.props.frameRate; + } + render () { const { preview, src, inline, onOpenVideo, onCloseVideo, intl, alt, letterbox, fullwidth, detailed, sensitive, link, editable, blurhash } = this.props; const { containerWidth, currentTime, duration, volume, buffer, dragging, paused, fullscreen, hovered, muted, revealed } = this.state; -- cgit From 4dab236690034aaee497336bf52d51ba06f71b18 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Wed, 25 Nov 2020 15:47:23 +0100 Subject: Default to 25 fps for frame seeking if framerate information isn't known --- app/javascript/flavours/glitch/features/video/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/javascript/flavours/glitch/features/video') diff --git a/app/javascript/flavours/glitch/features/video/index.js b/app/javascript/flavours/glitch/features/video/index.js index 7e8996af4..92dcaf473 100644 --- a/app/javascript/flavours/glitch/features/video/index.js +++ b/app/javascript/flavours/glitch/features/video/index.js @@ -544,7 +544,7 @@ class Video extends React.PureComponent { return this.props.frameRate.split('/').reduce((p, c) => p / c); } - return this.props.frameRate; + return this.props.frameRate || 25; } render () { -- cgit