Skip to content

Commit

Permalink
Add playback rate props (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Renée Kooi <[email protected]>
  • Loading branch information
chidimi and goto-bus-stop authored Oct 17, 2022
1 parent 93756f8 commit e65539d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Vimeo from '@u-wave/react-vimeo';
| muted | bool | false | Starts in a muted state to help with autoplay |
| background | bool | false | Starts in a background state with no controls to help with autoplay |
| responsive | bool | false | Enable responsive mode and resize according to parent element (experimental) |
| playbackRate | number | | Specify playback rate (requires Vimeo PRO / Business account)
| speed | bool | false | Enable playback rate controls (requires Vimeo PRO / Business account) |
| keyboard | bool | true | Allows for keyboard input to trigger player events. |
| pip | bool | false | Show the picture-in-picture button in the controlbar and enable the picture-in-picture API. |
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ export interface VimeoProps {
*/
responsive?: boolean

/**
* Specify playback rate (requires Vimeo PRO / Business account)
*/
playbackRate?: number

/**
* Enable playback rate controls (requires Vimeo PRO / Business account)
*/
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Vimeo extends React.Component {
player.unload();
}
break;
case 'playbackRate':
player.setPlaybackRate(value);
break;
default:
// Nothing
}
Expand All @@ -119,7 +122,7 @@ class Vimeo extends React.Component {
* @private
*/
createPlayer() {
const { start, volume } = this.props;
const { start, volume, playbackRate } = this.props;

this.player = new Player(this.container, this.getInitialOptions());

Expand Down Expand Up @@ -154,6 +157,10 @@ class Vimeo extends React.Component {
if (typeof volume === 'number') {
this.updateProps(['volume']);
}

if (typeof playbackRate === 'number') {
this.updateProps(['playbackRate']);
}
}

/**
Expand Down Expand Up @@ -293,6 +300,11 @@ if (process.env.NODE_ENV !== 'production') {
*/
responsive: PropTypes.bool,

/**
* Specify playback rate (requires Vimeo PRO / Business account)
*/
playbackRate: PropTypes.number,

/**
* Enable playback rate controls (requires Vimeo PRO / Business account)
*/
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ describe('Vimeo', () => {
expect(playerMock.setHeight).toHaveBeenCalledWith(800);
});

it('should set the playback rate using the "playbackRate" props', async () => {
const { playerMock, rerender } = render({
video: 169408731,
playbackRate: 0.5,
});

expect(playerMock.setPlaybackRate).toHaveBeenCalledWith(0.5);

await rerender({ playbackRate: 2 });

expect(playerMock.setPlaybackRate).toHaveBeenCalledWith(2);
});

it('should destroy player when unmounting', async () => {
const { playerMock, unmount } = render({
video: 169408731,
Expand Down
1 change: 1 addition & 0 deletions test/util/createVimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function createVimeo({ shouldFail = false } = {}) {
: Promise.resolve();
},
setVolume: createPromiseSpy(),
setPlaybackRate: createPromiseSpy(),
setCurrentTime: createPromiseSpy(),
setAutopause: createPromiseSpy(),
setColor: createPromiseSpy(),
Expand Down

0 comments on commit e65539d

Please sign in to comment.