Certainly! Let's address each issue and suggestion in turn, covering both bug fixes and enhancements. I’ll provide conceptual solutions and sample JavaScript where appropriate, assuming integration into a custom player or when extending a third-party (e.g., Video.js) is possible.
1. Video playback speed is reset on page load
Issue: The user's preferred speed is saved in localStorage but not re-applied on new page loads.
Solution: On player initialization, check localStorage for any saved playback rate and apply it. For example, if you're using the HTML5 video element:
// On player ready or page load
const video = document.querySelector('video');
const savedSpeed = localStorage.getItem('playbackRate');
if (savedSpeed) {
video.playbackRate = parseFloat(savedSpeed);
}
// When user changes speed
video.onratechange = function () {
localStorage.setItem('playbackRate', video.playbackRate);
};
If you’re using a video library, use its respective API/hooks to get/set playback rate.
2. Fullscreen player gives error on auto-advance
Issue: Changing videos while the player is in fullscreen causes playback URL errors, likely due to player teardown/reinit while in fullscreen.
Solution:
- Option 1: On advancing to the next video programmatically, first exit fullscreen:
function exitFullscreenIfActive() {
if (document.fullscreenElement) {
document.exitFullscreen();
}
}
// Call this right before loading the next video
exitFullscreenIfActive();
- Option 2: Refactor the way the new video source is set so the player doesn’t need to be re-initialized, or decouple the DOM teardown from fullscreen state.
3. Theater mode (as fallback to fullscreen)
Suggestion: Offer a "theater mode" that expands video to full content width but isn’t fullscreen.
Solution:
- Add a CSS class to toggle theater mode:
.theater-mode {
width: 100vw;
height: 80vh; /* adjust as needed */
margin: 0 auto;
background: #000;
z-index: 50; /* or however needed */
}
- Toggle it with a button:
document.getElementById('theater-btn').onclick = function () {
document.querySelector('.player-container').classList.toggle('theater-mode');
};
4. Double-click does not toggle fullscreen
Enhancement: Users expect to double-click the video to toggle fullscreen.
Solution:
const video = document.querySelector('video');
video.ondblclick = function () {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
video.requestFullscreen();
}
};
If using a custom overlay, bind the handler to the relevant container.
5. Easier rewatch experience
Issue: When revisiting a completed lesson, the video starts at the end.
Solution:
- Option 1: Add a "Rewatch" button.
<button onclick="rewatchVideo()">Rewatch</button>
function rewatchVideo() {
const video = document.querySelector('video');
video.currentTime = 0;
video.play();
}
- Option 2: Auto-reset if video loads at the end.
const video = document.querySelector('video');
video.addEventListener('loadedmetadata', function () {
if (video.currentTime >= video.duration - 1) { // within last second
video.currentTime = 0;
}
});
Summary
Each of these improvements is relatively straightforward with access to the player JavaScript and markup. Most issues stem from managing player state and session persistence; the above code blocks address the most common traps.
Note: Any implementation should be adapted to fit the specific player/library/framework that Laracasts uses (e.g., Video.js, Plyr, custom), but the provided examples are standard JavaScript and will work generally with HTML5 <video>.
Thank you for sharing your feedback and suggestions for Laracasts. These usability details make a big difference to daily users!