I want to store video duration
and ``src to local storage, but this code not working. The video src
and duration
showing in inspect element application local storage but not working for the video player.
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").src;
if (getSrc) {
mainVideo.src = getSrc;
mainVideo.currentTime = getDuration;
}
});
CodePudding user response:
One problem certainly lays right here
localStorage.getItem("src").src
You are trying to read the property src
but localStorage.getItem("src")
returns a string
or null
not an object
. Remove the .src
part and that error will be resolved.
I'm sorry if that wasn't your problem. If so please provide further information about your problem or any error messages.