2.2.8

Configuration

Last updated


This page lists every field of new FPlyr(config), the defaults, and how the initial volume and mute values are applied.

config


FieldTypeRequiredDescription
idstringNoID of an existing element that becomes the player container; if omitted or not found, a new div.FPlyr is created and player.body must be inserted manually
videostringOne ofVideo URL
youtubestringOne ofYouTube video ID
vimeostringOne ofVimeo video ID
audiostringOne ofAudio URL
optionobjectNoPanel and playback options, see below
whenobjectNoLifecycle callbacks, see Lifecycle Events

For the priority order when several sources are set, see Media Sources.

option


FieldTypeDefaultDescription
panelTypestring""Panel theme, see Panel Themes
panelItemstring[]["play", "progress", "time", "volumeMini", "rate", "full"]Controls, see Panel Controls
showThumbbooleantrueShow slider drag thumbs
volumenumber100Initial volume (0–100), see How volume and mute Are Applied
mutebooleanfalseInitial mute, see How volume and mute Are Applied

Without an id


Without id, the player stays off the page until you insert player.body:
  1. <section id="mount" style="max-width: 480px; aspect-ratio: 16 / 9"></section>
  2. <script>
  3. const player = new FPlyr({
  4. video: "https://cdn.pixabay.com/video/2023/11/28/191159-889246512_tiny.mp4",
  5. option: { panelType: "simple" },
  6. });
  7. console.log("attached before append:", player.body.isConnected);
  8. document.getElementById("mount").appendChild(player.body);
  9. console.log("attached after append:", player.body.isConnected);
  10. console.log("class:", player.body.className);
  11. </script>
Live preview · @pardnchiu/flexplyr@2.2.9

Invalid Config


If config is not an object, the constructor logs config: 不存在。 with console.log and returns without throwing; the instance has no body:
  1. <script>
  2. const player = new FPlyr("player");
  3. console.log("body:", String(player.body));
  4. </script>
Live preview · @pardnchiu/flexplyr@2.2.9

How volume and mute Are Applied


  • option.volume: the constructor writes it when the top-level volume is passed alongside it (src/js/model/player.js:61); with option alone the volume is 100.
  • option.mute: written the same way from the top-level mute (:65). At readiness the player applies the volume (:424), and any volume above 0 sets the player unmuted (:243), so the player starts unmuted; to silence it, the viewer presses the mute button of the volume control (Panel Controls) or drag the volume to 0.

  1. <div style="max-width: 480px; aspect-ratio: 16 / 9; margin-bottom: 12px"><div id="a"></div></div>
  2. <div style="max-width: 480px; aspect-ratio: 16 / 9"><div id="b"></div></div>
  3. <script>
  4. const a = new FPlyr({
  5. id: "a",
  6. video: "https://cdn.pixabay.com/video/2023/11/28/191159-889246512_tiny.mp4",
  7. option: { volume: 30, mute: true },
  8. when: { ready: () => setTimeout(() => console.log("option only ->", a.option.volume, a.isMuted())) },
  9. });
  10. const b = new FPlyr({
  11. id: "b",
  12. video: "https://cdn.pixabay.com/video/2023/11/28/191159-889246512_tiny.mp4",
  13. volume: 30,
  14. mute: true,
  15. option: { volume: 30, mute: true },
  16. when: { ready: () => setTimeout(() => console.log("option + legacy ->", b.option.volume, b.isMuted())) },
  17. });
  18. </script>
Live preview · @pardnchiu/flexplyr@2.2.9


中文