2.2.8

Instance API

Last updated


This page lists the public methods and properties of an FPlyr instance, plus the globals and ESM exports.

Methods


MethodReturnsDescription
play(isFull?)voidPlays and switches the play button to the pause icon; with isFull set to true on mobile, plays through the fullscreen player
pause(isFull?)voidPauses and switches the button back to the play icon
isPaused(isFull?)booleanWhether playback is paused; for YouTube, whether the player state is not 1
isMuted(isFull?)booleanWhether audio is muted
destroy()voidReleases the player in the order below

These methods branch on source flags that are set only at readiness, so calling them before when.ready fires, or synchronously inside ready, returns undefined and does not reach the media (see Lifecycle Events).

What destroy() Releases, in Order


  1. Removes the container's mousemove/mouseleave handlers
  2. Stops the progress poll
  3. Vimeo/YouTube call the SDK's destroy() (YouTube also destroys its fullscreen player); HTML5 media is paused and its src cleared
  4. Removes the container from the DOM
  5. Calls when.destroyed if it is a function

Properties


PropertyTypeDescription
bodyDOM elementPlayer container (.FPlyr)
optionobjectMerged option; after readiness, volume tracks volume changes
whenobjectLifecycle callbacks (when or the legacy event)
panelplayerPanelControl panel instance exposing elements such as buttonPlay and inputProgress
stateFullbooleanWhether the player is in fullscreen
video/youtube/vimeo/audiostringThe source actually used; the others are undefined

Example


  1. <div style="max-width: 480px; aspect-ratio: 16 / 9"><div id="player"></div></div>
  2. <button id="destroy">destroy()</button>
  3. <script>
  4. const player = new FPlyr({
  5. id: "player",
  6. video: "https://cdn.pixabay.com/video/2023/11/28/191159-889246512_tiny.mp4",
  7. when: {
  8. ready: () => setTimeout(() => {
  9. console.log("isPaused:", player.isPaused());
  10. console.log("isMuted:", player.isMuted());
  11. console.log("option:", JSON.stringify(player.option));
  12. }),
  13. destroyed: () => console.log("destroyed, in DOM:", player.body.isConnected),
  14. },
  15. });
  16. document.getElementById("destroy").onclick = () => player.destroy();
  17. </script>
Live preview · @pardnchiu/flexplyr@2.2.9

Globals and Exports


NameSourceDescription
window.FPlyrdist/FlexPlyr.jsMain class
window.PDPlayerdist/FlexPlyr.jsLegacy alias of FPlyr, scheduled for removal in 3.x
FPlyrdist/FlexPlyr.esm.jsESM named export
playerdist/FlexPlyr.esm.jsLegacy alias of FPlyr, scheduled for removal in 3.x

  1. import { FPlyr } from "@pardnchiu/flexplyr/dist/FlexPlyr.esm.js";


中文