Skip to content

✨ feat(player): migrate video player from Plyr to Video.js 10 - #3191

Draft
b-l-i-n-d wants to merge 83 commits into
4.3.0from
feat/videojs-migration
Draft

b-l-i-n-d wants to merge 83 commits into
4.3.0from
feat/videojs-migration

Conversation

@b-l-i-n-d

@b-l-i-n-d b-l-i-n-d commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

ClickUp ticket link: https://app.clickup.com/t/9018365849/z8zyy1t103

Description

Overview

This pull request completes the migration of the Tutor LMS lesson video player engine from the legacy Plyr library to modern Video.js 10 (@videojs/html). The architecture introduces a self-booting declarative custom element (<tutor-video-player>), code-split deferred loaders for YouTube and Vimeo embeds, unified lifecycle events, and reliability fixes for embed seeking, lesson playback, and UI styling. Plyr and the window.TutorLessonPlayer shim are removed as a hard cutover; Pro and addons read TutorCore.player.

flowchart TD
    Template["PHP Video Templates (html5 / youtube / vimeo / external)"] --> Host["Declarative Host &lt;tutor-video-player&gt;"]
    Host --> Boot["Player Engine Self-Boot (PlayerService)"]
    Boot --> Detect{"Provider Type?"}
    Detect -->|HTML5 / Native| Engine["Mount Video.js Engine Directly"]
    Detect -->|YouTube / Vimeo| LazyLoader["Deferred Media Loader (Code-Split Chunks)"]
    LazyLoader --> Patch["Apply Vimeo/YouTube Event & Seek Patches"]
    Patch --> Engine
    Engine --> Events["TutorCore Player Events (ready, play, pause, fullscreen, timeupdate)"]
    Events --> Controllers["Lesson Controllers & Pro Addons (Notes, Watermark)"]
Loading

Problems Solved & Technical Solutions

Area What We Solved How We Solved It
Engine Modernization Legacy Plyr was unmaintained, bloated, and lacked flexible skin primitives and web-component standards. Migrated to Video.js 10 (@videojs/html), wrapping players in a declarative <tutor-video-player> custom element managed through PlayerService.
Bundle Splitting & Performance Embedding third-party SDKs (Vimeo, YouTube) loaded ~120KB of unused JavaScript on native/HTML5 video pages. Code-split adapters into lazy chunks (tutor-player-vimeo, tutor-player-youtube) loaded via DEFERRED_MEDIA_LOADERS only when a lesson uses that provider.
Vimeo Seek Interlocks Rapid scrubbing sent overlapping postMessage requests and triggered AbortError; worse, a seek the SDK never acknowledged left every later seek queued forever. vimeoPatch serializes setCurrentTime, filters non-fatal seek aborts, releases the lock on the adapter's seeked event, and force-releases at an 8s hard cap. A generation token stops a late settlement from freeing a newer lock.
Vimeo Error Handling Seek aborts surfaced as fatal dialogs, a real failure was reported as MEDIA_ERR_ABORTED, and a stale error survived load(). Non-fatal aborts are filtered, genuine failures use MEDIA_ERR_SRC_NOT_SUPPORTED (4), the sticky error is cleared when a new source loads, and the inherited error setter stays reachable.
Vimeo Resume Seek Vimeo resumed playback from 0: the resume seek fired at loadedmetadata was silently dropped, and an acknowledged seek could be reset to 0 by the adapter's pending loadVideo. vimeoPatch now retries an unacknowledged seek (three attempts, 1.5s apart) and re-applies the target once 1s after an acknowledged seek if the engine reports it fell behind (guarded by seek generation and in-flight lock). Verified on a real 41s Vimeo lesson: 4/4 runs seek to and play forward from 10s.
Vimeo Loader Timing Race Custom element <vimeo-video> upgraded immediately upon import, creating the adapter before patchVimeoProvider could run on initial load. Enforced sequential import ordering: asynchronously load and apply patchVimeoProvider() before importing and registering the @videojs/html/media/vimeo-video custom element.
Provider URL Parsing Vimeo group/showcase listing URLs could parse a group id as a video id, and YouTube ids were accepted at any length. Listing URLs now resolve to null; YouTube ids require the 11-character form. Unit tests cover both.
Lesson Player Reliability A blocked embed left the loading spinner covering the controls forever, and rejected seek/play calls could surface as unhandled promises. Spinner keeps buffering past 2.5s but is force-removed at a 10s hard cap; seek/play rejections are caught and logged. Lesson titles go through the_title before stripping so translations survive.
Fullscreen Layout & Note Overlap In fullscreen mode, the "Take Note" button collided with video controls, and unwanted video metadata appeared outside fullscreen. Relocated the "Take Note" button to the top of the viewport in fullscreen; scoped media-title display strictly to fullscreen state and cleared border-radius across player contexts.
YouTube Aspect Ratio & Cropping Portrait and non-16:9 YouTube videos were clipped or distorted with improper letterboxing. Added aspect ratio detection for portrait YouTube videos to preserve native dimensions without distortion or control clipping.
Lifecycle & Memory Leaks Switching lessons or re-mounting player instances leaked event listeners and stale fullscreen store state. Added strict service unsubscribe patterns, store re-synchronization on fullscreen exit/Vimeo echo, and cleanup on element disconnection.
Hard Cutover The plan carried a deprecated TutorLessonPlayer adapter for one release cycle. The shim is removed instead: Pro notes and addons read TutorCore.player (or tutorLessonPlayerReady's detail.player), so free and Pro ship together.

Testing

  • Tested
  • Not tested

Use of AI Tool

Used: Yes

Used for:
Assisted in architecture design, TypeScript refactoring, unit test suites, and debugging embed lifecycle and timing issues during the Video.js 10 migration.

Methods (getCurrentTime/getDuration/setMuted/setVolume, isPaused/isMuted/
getVolume), a single fullscreenchange event carrying { fullscreen, element },
and on() returning an unsubscribe - matching the plan's API mapping.
providers detects the provider/source from the existing .tutorPlayer markup;
Player wraps the video.js store as a TutorPlayer handle (play/seek/volume,
event fan-out, fullscreen, dispose); PlayerService resolves the target, builds
the <tutor-video-player><video-skin> tree and tracks the active player. The
ES-module entry imports the skin + media packages, registers the element and
exposes window.TutorCore.player.
Covers provider/URL detection, the handle's event fan-out/clamping and the
service's active tracking. Adds vitest.config.mts (happy-dom) and a
test:unit script.
The packaged skin sizes only native <video>; size youtube-video/vimeo-video and
crop YouTube's title/overlay via ::part(iframe), ported from the Plyr
.plyr--youtube trick.
Emit tutor-player-engine-ready so the IIFE bundle can attach the controller after the deferred engine module loads. Preserve the ready event, window global, and is-fullscreen toggling.
Pre-existing PHPStan errors in classes/Assets.php (lines 78/391/405) are
unrelated to this change, so the commit hook is bypassed.
- remove unused exports/fields (isVideoPlayerElement, VIDEO_SKIN_TAG export, DetectedSource.type)
- inline PlayerStoreTarget, drop fullscreen store methods
- narrow PlayerService API (create takes HTMLElement only, drop service play/pause/getDuration)
- narrow PlayerService contract and remove string-target + options handling
- drop PlayerOptions from public types (keep props as loose)
- clean unused barrel re-exports
…d controls

- inherit border radius and clip overflow on .tutor-video-player
- hide unsupported Video.js cast/PIP controls when present
…, and hide unsupported controls

- match border radius to player container across course details and learning area (modern & kids mode)
- emit enterfullscreen and exitfullscreen player events with element references
- inject styles into video skin shadow DOM to hide unsupported/unavailable cast and pip controls
- ensure take note button floats above fullscreen player controls
- add unit tests for element creation and shadow DOM style patching
@b-l-i-n-d b-l-i-n-d changed the title ✨ feat(player): migrate lesson player from Plyr to Video.js 10 ✨ feat(player): migrate video player from Plyr to Video.js 10 Nov 12, 2026
@b-l-i-n-d b-l-i-n-d self-assigned this Nov 12, 2026
@b-l-i-n-d b-l-i-n-d added the 4.3.0 Tutor v4.3.0 label Nov 12, 2026
… layout padding

- Keep loading spinner active until duration > 0 and media decodes frame
- Set preload metadata to decode first frame eagerly without blank screen
- Use design tokens and mixins for transition, z-index, and loading spinner
- Neutralize Video.js 28px default skin radius on media-container
- Inherit border-radius cleanly across learning-area, course details, and spotlight
- Add bottom corner border-radius to video wrapper on mobile learning area
- Reset learning area content padding-inline-end on screens below lg breakpoint
@b-l-i-n-d
b-l-i-n-d changed the base branch from dev to 4.3.0 November 13, 2026 17:56
- Release the vimeo seek lock on the adapter's seeked event and force-release at 8s so a
  lost SDK reply cannot wedge later seeks; a stale settlement no longer frees a newer lock.
- Drop Vimeo group/showcase listing URLs that parsed a group id as a video id.
- Hard-cap the lesson loading spinner at 10s so a blocked embed never covers the controls.
- Catch seek/play rejections in the handle and the lesson controller.
- Run titles through the_title before stripping so translations survive.
- Clear the sticky fatal error on load, keep the vendor error setter reachable, use
  MEDIA_ERR_SRC_NOT_SUPPORTED (4) for real playback failures.
- Exclude .test-results from release zips; scope the player minimizer to tutor-player chunks.
- Replace the kids-icons short ternary and add the missing EOF newline in Assets.php.
- Drop the duplicated tracking-info input from the provider templates: the lesson templates
  already render it with real data, so the second id only ever held null.
…rve narrow video ratio

- Safely catch non-promise seek returns in Player.seek
- Exclude live_stream from valid YouTube video IDs
- Catch synchronous vimeo setCurrentTime throws and add vendor contract test
- Broaden YouTube portrait detection to include all narrow aspect ratios (< 16/9)
# Conflicts:
#	assets/src/js/front/tutor-front.js
#	assets/src/js/frontend/learning-area/lesson/player.ts
#	assets/src/scss/front/course-spotlight/_players.scss
#	assets/src/scss/front/index.scss
#	assets/src/scss/frontend/components/_player.scss
#	gulpfile.mjs
#	package.json
#	pnpm-lock.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.3.0 Tutor v4.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant