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

Persist playback rate #878

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mr-fixit
Copy link

see Slack thread

to test

view an episode, change video playback rate. (gear icon)
quit safari, relaunch, view a different episode, check its rate

expect: its playback rate will be what you last used

Copy link

@Matejkob Matejkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely love this feature! It’s going to be such a relief not having to manually adjust the playback rate to 2.0 for each episode—thank you for adding this!

I've left one comment inline regarding a minor enhancement, but overall, the code looks good to me (but I'm not a JS expert).

I'm really excited to see this merged as soon as possible, @mbrandonw @stephencelis what do u think? 😇

Comment on lines +70 to +74
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0
);
player.on('playbackratechange', function(data) {
localStorage.setItem('pf_playbackrate', data.playbackRate);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on JS, but this code looks solid to me. To make it even more bulletproof, we could ensure type safety by converting the value from localStorage to a number. Also, adding error handling when saving data to localStorage could be good, for example to handle a case when a user has disabled it.

Suggested change
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0
);
player.on('playbackratechange', function(data) {
localStorage.setItem('pf_playbackrate', data.playbackRate);
});
const defaultPlaybackRate = 1.0;
const playbackRate = parseFloat(localStorage.getItem('pf_playbackrate')) || defaultPlaybackRate;
player.setPlaybackRate(playbackRate);
player.on('playbackratechange', function(data) {
try {
localStorage.setItem('pf_playbackrate', String(data.playbackRate));
} catch (e) {
console.error('Failed to save playback rate:', e);
}
});

Comment on lines +103 to +106
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0);
player.on('playbackratechange', function(data) {
localStorage.setItem('pf_playbackrate', data.playbackRate);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I belive the same change can be done here:

Suggested change
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0);
player.on('playbackratechange', function(data) {
localStorage.setItem('pf_playbackrate', data.playbackRate);
});
const defaultPlaybackRate = 1.0;
const playbackRate = parseFloat(localStorage.getItem('pf_playbackrate')) || defaultPlaybackRate;
player.setPlaybackRate(playbackRate);
player.on('playbackratechange', function(data) {
try {
localStorage.setItem('pf_playbackrate', String(data.playbackRate));
} catch (e) {
console.error('Failed to save playback rate:', e);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants