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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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? 😇
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0 | ||
); | ||
player.on('playbackratechange', function(data) { | ||
localStorage.setItem('pf_playbackrate', data.playbackRate); | ||
}); |
There was a problem hiding this comment.
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.
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); | |
} | |
}); |
player.setPlaybackRate( localStorage.getItem('pf_playbackrate') || 1.0); | ||
player.on('playbackratechange', function(data) { | ||
localStorage.setItem('pf_playbackrate', data.playbackRate); | ||
}); |
There was a problem hiding this comment.
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:
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); | |
} | |
}); |
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