Preload
How much of a media file the browser fetches before the viewer presses play.
The preload attribute of the video and audio elements the
CkVideoPlayer and
CkAudioPlayer objects build: nothing, the
metadata, or the whole file. It is a hint, which the browser may ignore — on a metered
connection most fetch less than asked — and left unset, the browser decides.
Members
| Member | Meaning |
|---|---|
None |
Nothing until the viewer presses play: preload="none". For a page with many players, or a file few viewers will start. |
Metadata |
The metadata — the length, the size, the first frame — and no more: preload="metadata". The player shows its length and a frame before anything plays. |
Auto |
The whole file, when the browser agrees: preload="auto". For the one video a page is about. |
The enum is backed by an int — None is 0, Metadata 1, Auto 2 — so a choice can be
stored and read back with Preload::from().
Where it is used
The Preload setter of a CkVideoPlayer and
of a CkAudioPlayer, the elements
CkMedia::Video and CkMedia::Audio
hand back through Player(). The setter takes null too, which writes no attribute and leaves
the browser to decide — the state a player starts in. The two provider players, YouTube's and
Vimeo's, have no such choice: an iframe loads what the provider sends.
Quick look
use SafeCoder\CommonKit\CkMedia;
use SafeCoder\CommonKit\Enums\Preload;
CkMedia::Video('https://cdn.example.com/clip.mp4')->Player()->Preload(Preload::Metadata)->Html(); // -> '<video src="https://cdn.example.com/clip.mp4" preload="metadata" controls></video>'
CkMedia::Audio('https://cdn.example.com/talk.mp3')->Player()->Preload(Preload::None)->Html(); // -> '<audio src="https://cdn.example.com/talk.mp3" preload="none" controls></audio>'
CkMedia::Video('https://cdn.example.com/clip.mp4')->Player()->Preload(null)->Html(); // -> '<video src="https://cdn.example.com/clip.mp4" controls></video>'