Skip to content

Refactor/Rename PlaybackObserver to MediaElementMonitor#1754

Open
peaBerberian wants to merge 1 commit intodevfrom
misc/renaming-playback-observer
Open

Refactor/Rename PlaybackObserver to MediaElementMonitor#1754
peaBerberian wants to merge 1 commit intodevfrom
misc/renaming-playback-observer

Conversation

@peaBerberian
Copy link
Copy Markdown
Collaborator

TL;DR: This is a code simplification proposal to set a single interface for all HTMLMediaElement interactions, under a class named MediaElementMonitor. This is just a merge of the previous PlaybackObserver module (which monitors playback) and of previously direct HTMLMediaElement access (which would now be avoided in profit of calling MediaElementMonitor methods).


Based on #1645

I worked on multiple R&D subjects recently that needed a re-thinking of how we interact with the media element in the core logic:

  • The "preload" work (to preload a content in-memory before playback).

    Here the idea was to make most core RxPlayer modules work optionally "headlessly" during a preloading phase (without an actual media element to play on), and to then be able to "hot swap" the media element at any point if the content needed to be actually played - with the intent of speeding up loading time for future contents.

  • The "Core Dump" work (a planned API to output an extensive snapshot of the RxPlayer state and playback conditions on playback errors - for debugging, logging and advanced experimental mitigations purposes of platform issues).

    Here I needed to be able to access many media properties at once and both their current states but also their last pre-error status.

On both of those subjects, I found that passing around both the media element and a PlaybackObserver everywhere was awkward and unnecessary: the PlaybackObserver already contains the media element and has to be used for some side-effects: e.g. seeking has to go through it.

So I propose here to just define a single interface to the media element.

The most difficult step has been to know what to name that thing. Initially I went with MediaElementInterface, but it didn't seem to be really indicative of what 99% of its use is, which is to monitor playback conditions.
So in the end I just went with MediaElementMonitor. Though it also allows side-effect on the media element (seeking, setting src...)

Not everything is simplified yet (there are still places when I rely on the two), but it's a good first step.

@peaBerberian peaBerberian added the Priority: 3 (Low) This issue or PR has a low priority. label Oct 7, 2025
@peaBerberian peaBerberian added this to the 4.5.0 milestone Oct 7, 2025
@peaBerberian peaBerberian force-pushed the poc/common-init-renaming branch from af6e10d to b7b34ed Compare October 9, 2025 14:18
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from 6652566 to 0fa2c02 Compare October 9, 2025 14:20
@peaBerberian peaBerberian changed the base branch from poc/common-init-renaming to dev October 9, 2025 17:26
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from 0fa2c02 to d725569 Compare October 9, 2025 17:26
@peaBerberian peaBerberian force-pushed the dev branch 4 times, most recently from 6cfd206 to 1e55170 Compare October 13, 2025 20:54
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch 7 times, most recently from ba8892f to 5833b27 Compare October 31, 2025 14:54
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from 5833b27 to 950fc06 Compare November 12, 2025 14:43
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from 950fc06 to ec1a402 Compare December 10, 2025 15:12
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from ec1a402 to aebf9df Compare December 10, 2025 17:25
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions bot Dec 19, 2025
@peaBerberian peaBerberian force-pushed the dev branch 2 times, most recently from d4be192 to 9ad6758 Compare December 19, 2025 19:49
@peaBerberian peaBerberian removed this from the 4.5.0 milestone Jan 19, 2026
@peaBerberian peaBerberian force-pushed the dev branch 9 times, most recently from 0142e34 to 1fd9df3 Compare January 27, 2026 11:59
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from aebf9df to 3a39679 Compare February 27, 2026 14:05
**TL;DR: This is a code simplification proposal to set a single
interface for all `HTMLMediaElement` interactions, under a class named
`MediaElementMonitor`. This is just a merge of the previous
`PlaybackObserver` module (which monitors playback) and of previously
direct `HTMLMediaElement` access (which would now be avoided in profit
of calling `MediaElementMonitor` methods).**

---

I worked on multiple R&D subjects recently that needed a re-thinking of
how we interact with the media element in the core logic:

- The "preload" work (to preload a content in-memory before playback).

  Here the idea was to make most core RxPlayer modules work optionally
  "headlessly" during a preloading phase (without an actual media
  element to play on), and to then be able to "hot swap" the media
  element at any point if the content needed to be actually played -
  with the intent of speeding up loading time for future contents.

- The "Core Dump" work (a planned API to output an extensive snapshot
  of the RxPlayer state and playback conditions on playback errors - for
  debugging, logging and advanced experimental mitigations purposes of
  platform issues).

  Here I needed to be able to access many media properties at once and
  both their current states but also their last pre-error status.

On both of those subjects, I found that passing around both the media
element and a `PlaybackObserver` everywhere was awkward and unnecessary:
the `PlaybackObserver` already contains the media element and has to be
used for some side-effects: e.g. seeking has to go through it.

So I propose here to just define a single interface to the media
element.

The most difficult step has been to know what to name that thing.
Initially I went with `MediaElementInterface`, but it didn't seem to be
really indicative of what 99% of its use is, which is to monitor
playback conditions.
So in the end I just went with `MediaElementMonitor`. Though it also
allows side-effect on the media element (seeking, setting `src`...)

Not everything is simplified yet (there are still places when I rely on
the two), but it's a good first step.
@peaBerberian peaBerberian force-pushed the misc/renaming-playback-observer branch from 3a39679 to 5f6238c Compare February 27, 2026 15:39
@github-actions
Copy link
Copy Markdown

✅ Automated performance checks have passed on commit 8ffc5149e40b5cf8ec5609e1c459b2806c68ca16 with the base branch dev.

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 25.25ms -> 25.64ms (-0.388ms, z: 3.85618) 35.85ms -> 36.15ms
seeking 333.65ms -> 370.99ms (-37.332ms, z: 3.00636) 17.30ms -> 16.95ms
audio-track-reload 32.50ms -> 31.94ms (0.565ms, z: 7.00486) 48.45ms -> 47.55ms
cold loading multithread 51.63ms -> 50.83ms (0.801ms, z: 13.39402) 76.50ms -> 75.15ms
seeking multithread 51.24ms -> 54.68ms (-3.442ms, z: 1.67625) 20.40ms -> 20.55ms
audio-track-reload multithread 30.83ms -> 30.78ms (0.053ms, z: 1.65145) 45.30ms -> 45.15ms
hot loading multithread 20.44ms -> 20.30ms (0.141ms, z: 3.43105) 30.00ms -> 29.85ms

@canalplus canalplus deleted a comment from github-actions bot Feb 27, 2026
@canalplus canalplus deleted a comment from github-actions bot Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: 3 (Low) This issue or PR has a low priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant