Proposal: ContentInitializer: remove explicit two-steps of prepare and start#1762
Open
peaBerberian wants to merge 1 commit intodevfrom
Open
Proposal: ContentInitializer: remove explicit two-steps of prepare and start#1762peaBerberian wants to merge 1 commit intodevfrom
ContentInitializer: remove explicit two-steps of prepare and start#1762peaBerberian wants to merge 1 commit intodevfrom
Conversation
80414c4 to
7309422
Compare
7309422 to
5e8bd1f
Compare
a42734c to
29372ac
Compare
Since we brought the idea of allowing a `PlaybackObserver` to be
without a media element attached (e.g. when a previous content is
still not stopped), we have an occasion to simplify the
`ContentInitializer` API a little:
Instead of having two methods `prepare` (non-destructive content
preparation, e.g. manifest fetching) and `start` ("destructive"
playback, in that the previous content will be stopped), we can know
just have one exposed API and make it itself await for media element
attachment to know when it's able to actually play.
i.e. instead of:
```js
const init = new ContentInitializer({ /* ... */ });
const playbackObserver = new PlaybackObserver({ /* ... */})
// ... Link callbacks to `init`s events.
init.prepare();
// ... Stop previous content
playbackObserver.attachMediaElement(mediaElement);
// ... Ensure media element is ready to play a new content -
// (specifically clean some DRM state is needed)
init.start(mediaElement, playbackObserver);
```
We can now just do:
```js
const init = new ContentInitializer({ /* ... */ });
const playbackObserver = new PlaybackObserver({ /* ... */})
// ... Link callbacks to `init`s events.
init.start(playbackObserver);
// ... Stop previous content
// ... Ensure media element is ready to play a new content -
// (specifically clean some DRM state is needed)
playbackObserver.attachMediaElement(mediaElement);
```
(`preprare` is renamed `start`, old `start` is removed,
`attachMediaElement` is just done later).
Though this does mean a supplementary `PlaybackObserver` method - here
called `onMediaElementAttachment(callback, cancelSignal)` that the
`ContentInitializer` has to know about and called. This also means that
it now understands the idea that a `PlaybackObserver` might not have a
media element attached at first.
---
Note that even if it can look like it, this is not at all linked to our
potential "preload" feature.
This is just a possible alternative `ContentInitializer` API that I
wanted to illustrate since we did the
"PlaybackObserver-without-media-element" thing.
5e8bd1f to
78b8cda
Compare
|
✅ Automated performance checks have passed on commit DetailsPerformance tests 1st run outputNo significative change in performance for tests:
|
d4be192 to
9ad6758
Compare
0142e34 to
1fd9df3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since we brought the idea of allowing a
PlaybackObserverto be without a media element attached (e.g. when a previous content is still not stopped), we have an occasion to simplify theContentInitializerAPI a little:Instead of having two methods
prepare(non-destructive content preparation, e.g. manifest fetching) andstart("destructive" playback, in that the previous content will be stopped), we can now just have one exposed API and make it itself await for media element attachment to know when it's able to actually play.i.e. instead of:
We can now just do:
(
preprareis renamedstart, oldstartis removed,attachMediaElementis just done later).Though this does mean a supplementary
PlaybackObservermethod - here calledonMediaElementAttachment(callback, cancelSignal)that theContentInitializerhas to know about and call. This also means that it now understands the idea that aPlaybackObservermight not have a media element attached at first.Also
playbackObserver.attachMediaElement()now needs to be called only once the media element can actually play a content, not just when its properties seem clean enough. But IMO for that part, it's cleaner and more understandable that way than before.Note that even if it can look like it, this is not at all linked to our potential "preload" feature.
This is just a possible alternative
ContentInitializerAPI that I wanted to illustrate since we did the"PlaybackObserver-without-media-element" thing.