Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YoutubeVideo): implement playbackSpeed #49

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/YouTubeVideo/YouTubeVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function YouTubeVideo(options) {
onPropChanged('time');
onPropChanged('volume');
onPropChanged('muted');
onPropChanged('playbackSpeed');
}, timeChangedTimeout);

var video = null;
Expand All @@ -46,6 +47,7 @@ function YouTubeVideo(options) {
buffering: false,
volume: false,
muted: false,
playbackSpeed: false,
subtitlesTracks: false,
selectedSubtitlesTrackId: false
};
Expand Down Expand Up @@ -165,6 +167,7 @@ function YouTubeVideo(options) {
onPropChanged('buffering');
onPropChanged('volume');
onPropChanged('muted');
onPropChanged('playbackSpeed');
onPropChanged('subtitlesTracks');
onPropChanged('selectedSubtitlesTrackId');
}
Expand Down Expand Up @@ -240,6 +243,13 @@ function YouTubeVideo(options) {

return video.isMuted();
}
case 'playbackSpeed': {
if (stream === null || typeof video.getPlaybackRate !== 'function' || video.getPlaybackRate() === null || !isFinite(video.getPlaybackRate())) {
return null;
}

return video.getPlaybackRate();
}
case 'subtitlesTracks': {
if (stream === null || typeof video.getOption !== 'function') {
return [];
Expand Down Expand Up @@ -335,6 +345,14 @@ function YouTubeVideo(options) {

break;
}
case 'playbackSpeed': {
if (stream !== null && typeof video.setPlaybackRate === 'function' && isFinite(propValue)) {
video.setPlaybackRate(propValue);
onPropChanged('playbackSpeed');
}

break;
}
case 'selectedSubtitlesTrackId': {
if (stream !== null) {
selectedSubtitlesTrackId = null;
Expand Down Expand Up @@ -388,6 +406,7 @@ function YouTubeVideo(options) {
onPropChanged('buffering');
onPropChanged('volume');
onPropChanged('muted');
onPropChanged('playbackSpeed');
onPropChanged('subtitlesTracks');
onPropChanged('selectedSubtitlesTrackId');
} else {
Expand Down Expand Up @@ -417,6 +436,7 @@ function YouTubeVideo(options) {
onPropChanged('buffering');
onPropChanged('volume');
onPropChanged('muted');
onPropChanged('playbackSpeed');
onPropChanged('subtitlesTracks');
onPropChanged('selectedSubtitlesTrackId');
break;
Expand Down Expand Up @@ -477,7 +497,7 @@ YouTubeVideo.canPlayStream = function(stream) {
YouTubeVideo.manifest = {
name: 'YouTubeVideo',
external: false,
props: ['stream', 'loaded', 'paused', 'time', 'duration', 'buffering', 'volume', 'muted', 'subtitlesTracks', 'selectedSubtitlesTrackId'],
props: ['stream', 'loaded', 'paused', 'time', 'duration', 'buffering', 'volume', 'muted', 'playbackSpeed', 'subtitlesTracks', 'selectedSubtitlesTrackId'],
commands: ['load', 'unload', 'destroy'],
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded']
};
Expand Down
Loading