From 292f3cd7e0db0d71cb3202e65185f06fd04c475f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 8 Oct 2017 02:33:08 +0200 Subject: [PATCH] Show buffering in video player (#5261) --- app/javascript/mastodon/features/video/index.js | 10 ++++++++-- app/javascript/styles/components.scss | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/features/video/index.js b/app/javascript/mastodon/features/video/index.js index 7502dda8b..519a2aac9 100644 --- a/app/javascript/mastodon/features/video/index.js +++ b/app/javascript/mastodon/features/video/index.js @@ -209,6 +209,10 @@ export default class Video extends React.PureComponent { } } + handleProgress = () => { + this.setState({ buffer: this.video.buffered.end(0) / this.video.duration * 100 }); + } + handleOpenVideo = () => { this.video.pause(); this.props.onOpenVideo(this.video.currentTime); @@ -221,7 +225,7 @@ export default class Video extends React.PureComponent { render () { const { preview, src, width, height, startTime, onOpenVideo, onCloseVideo, intl, alt } = this.props; - const { progress, dragging, paused, fullscreen, hovered, muted, revealed } = this.state; + const { progress, buffer, dragging, paused, fullscreen, hovered, muted, revealed } = this.state; return (
@@ -229,7 +233,7 @@ export default class Video extends React.PureComponent { ref={this.setVideoRef} src={src} poster={preview} - preload={!!startTime} + preload={startTime ? true : null} loop role='button' tabIndex='0' @@ -241,6 +245,7 @@ export default class Video extends React.PureComponent { onPause={this.handlePause} onTimeUpdate={this.handleTimeUpdate} onLoadedData={this.handleLoadedData} + onProgress={this.handleProgress} />