Skip to content

Commit 0865835

Browse files
authored
Fix #43 where seek bar and volume control feel janky (#45)
1 parent e19ecae commit 0865835

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/components/controls/mute/Mute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var Mute = React.createClass({
3333
* @return {undefined}
3434
*/
3535
changeVolume(e) {
36-
this.props.setVolume(e.target.value / 100);
36+
this.props.setVolume(e.target.value / 100, true);
3737
this.props.unmute();
3838
},
3939

src/components/controls/seek/Seek.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Seek = React.createClass({
4040
* @return {undefined}
4141
*/
4242
seek(e) {
43-
this.props.seek(e.target.value * this.props.duration / 100);
43+
this.props.seek(e.target.value * this.props.duration / 100, true);
4444
},
4545

4646
onFocus() {

src/components/video/Video.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,37 @@ var Video = React.createClass({
196196
/**
197197
* Seeks the video timeline.
198198
* @param {number} time The value in seconds to seek to
199+
* @param {bool} forceUpdate Forces a state update without waiting for
200+
* throttled event.
199201
* @return {undefined}
200202
*/
201-
seek(time) {
203+
seek(time, forceUpdate) {
202204
this.videoEl.currentTime = time;
205+
// In some use cases, we wish not to wait for `onSeeked` or `onSeeking`
206+
// throttled event to update state so we force it. This is because
207+
// this method is often triggered when dragging a bar and can feel janky.
208+
// See https://github.com/mderrick/react-html5video/issues/43
209+
if (forceUpdate) {
210+
this.updateStateFromVideo();
211+
}
203212
},
204213

205214
/**
206215
* Sets the video volume.
207216
* @param {number} volume The volume level between 0 and 1.
217+
* @param {bool} forceUpdate Forces a state update without waiting for
218+
* throttled event.
208219
* @return {undefined}
209220
*/
210-
setVolume(volume) {
221+
setVolume(volume, forceUpdate) {
211222
this.videoEl.volume = volume;
223+
// In some use cases, we wish not to wait for `onVolumeChange`
224+
// throttled event to update state so we force it. This is because
225+
// this method is often triggered when dragging a bar and can feel janky.
226+
// See https://github.com/mderrick/react-html5video/issues/43
227+
if (forceUpdate) {
228+
this.updateStateFromVideo();
229+
}
212230
},
213231

214232
/**

0 commit comments

Comments
 (0)