Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add custom options #2830

Open
anime-kun32 opened this issue Dec 4, 2024 · 2 comments
Open

How do I add custom options #2830

anime-kun32 opened this issue Dec 4, 2024 · 2 comments

Comments

@anime-kun32
Copy link

anime-kun32 commented Dec 4, 2024

Hi I'm trying to add new options in plyr's settings menu , the place were we find speed and caption
does plyr support this if so how do I do this

@anime-kun32
Copy link
Author

I tried it doing here ```html

<title>Custom 1 Video Player</title> <style> body { margin: 0; overflow: hidden; } .plyr { width: 100vw; height: 100vh; } </style> <script src="https://cdn.jsdelivr.net/npm/plyr@3"></script> <script>
const urlParams = new URLSearchParams(window.location.search);
const videoID = urlParams.get("id");

if (!videoID) {
  console.error("No video ID provided in the URL. Add '?id=VIDEO_ID' to the URL.");
}


const baseApiUrl = `https://tt57.biananset.net/_v7/${videoID}/master.m3u8`;


const player = new Plyr("#player", {
  controls: [
    "play-large", "play", "progress", "current-time", "mute", "volume", "captions",
    "settings", "fullscreen"
  ],
  settings: ["captions", "quality", "speed", "audio", "server"], // Custom menus
});


let audioCategory = "sub"; // Default
let selectedServer = "hd-1"; // Default
const servers = ["hd-1", "hd-2", "streamsb", "streamtape"];


function updateSource() {
  const apiUrl = `${baseApiUrl}?category=${audioCategory}&server=${selectedServer}`;
  player.source = {
    type: "video",
    sources: [{ src: apiUrl, type: "application/x-mpegURL" }],
  };
}

function addCustomControls() {

  const audioMenuItems = [
    { label: "Sub", value: "sub", checked: true },
    { label: "Dub", value: "dub" },
  ];
  player.config.settingsMenu.audio = audioMenuItems;


  const serverMenuItems = servers.map((server) => ({
    label: server,
    value: server,
    checked: server === selectedServer,
  }));
  player.config.settingsMenu.server = serverMenuItems;


  player.on("settingchanged", (event) => {
    if (event.detail.setting === "audio") {
      audioCategory = event.detail.value;
      updateSource();
    }
  });

  player.on("settingchanged", (event) => {
    if (event.detail.setting === "server") {
      selectedServer = event.detail.value;
      updateSource();
    }
  });
}


updateSource();
player.on("ready", addCustomControls);
</script> ```

@anime-kun32
Copy link
Author

but it doesen't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant