Skip to content

Commit

Permalink
Call setCurrentTime() after a new video has loaded. (#95)
Browse files Browse the repository at this point in the history
* Call `setCurrentTime()` after a new video has loaded.

Fixes #68

Apparently doing `setCurrentTime()` immediately is fine for the initial
load, but not when starting a new video.

* lint fix

* test: return Promises from spies
  • Loading branch information
goto-bus-stop committed Feb 29, 2020
1 parent ab63cac commit 54f66d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Expand Up @@ -88,10 +88,14 @@ class Vimeo extends React.Component {
case 'video':
if (value) {
const { start } = this.props;
player.loadVideo(value);
const loaded = player.loadVideo(value);
// Set the start time only when loading a new video.
// It seems like this has to be done after the video has loaded, else it just starts at
// the beginning!
if (typeof start === 'number') {
player.setCurrentTime(start);
loaded.then(() => {
player.setCurrentTime(start);
});
}
} else {
player.unload();
Expand Down
16 changes: 9 additions & 7 deletions test/util/createVimeo.js
Expand Up @@ -4,20 +4,22 @@ import proxyquire from 'proxyquire';
export default function createVimeo({ shouldFail = false } = {}) {
let isPaused = true;

const createPromiseSpy = () => createSpy().andCall(() => Promise.resolve());

const playerMock = {
on: createSpy(),
ready() {
return shouldFail
? Promise.reject(new Error('artificial failure'))
: Promise.resolve();
},
setVolume: createSpy(),
setCurrentTime: createSpy(),
setAutopause: createSpy(),
setColor: createSpy(),
setLoop: createSpy(),
loadVideo: createSpy(),
unload: createSpy(),
setVolume: createPromiseSpy(),
setCurrentTime: createPromiseSpy(),
setAutopause: createPromiseSpy(),
setColor: createPromiseSpy(),
setLoop: createPromiseSpy(),
loadVideo: createPromiseSpy(),
unload: createPromiseSpy(),
play: createSpy().andCall(() => {
isPaused = false;
}),
Expand Down

0 comments on commit 54f66d4

Please sign in to comment.