0

i have movie website and my video player local storage just saving one video src.

i want to use different src for each movie video

window.addEventListener("unload", () => {
    let setDuration = localStorage.setItem(
      "duration",
      `${mainVideo.currentTime}`
    );
    let setSrc = localStorage.setItem(
      "src",
      `${mainVideo.getAttribute("src")}`
    );
  });

  window.addEventListener("load", () => {
    let getDuration = localStorage.getItem("duration");
    let getSrc = localStorage.getItem("src");
    if (getSrc) {
      mainVideo.src = getSrc;
      mainVideo.currentTime = getDuration;
    }
  });
boyuna1720
  • 13
  • 4
  • The easiest modification would be to append an index to your keys, e.g., src-1, src-2, src-n. Yet, if you have many videos then you'll want to store them as an array of objects. See related question: [How to store an array of objects in Local Storage?](https://stackoverflow.com/questions/43762363/how-to-store-an-array-of-objects-in-local-storage) – Yogi Jan 16 '23 at 17:32
  • i do not know how to do this – boyuna1720 Jan 16 '23 at 21:32
  • The question does not provide enough detail to suggest a specific solution. However, I created a [JSFiddle](https://jsfiddle.net/5r9msvzw/2/show) that shows you how to save and restore the video state. Click the edit button on the page to view the code. – Yogi Jan 17 '23 at 00:48

0 Answers0