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

Remember playback state? #56

Open
orschiro opened this issue Aug 5, 2019 · 5 comments
Open

Remember playback state? #56

orschiro opened this issue Aug 5, 2019 · 5 comments

Comments

@orschiro
Copy link

orschiro commented Aug 5, 2019

Something default YouTube does.

Can the extension support this, too?

@orschiro
Copy link
Author

It seems this one can: https://github.com/craftwar/youtube-audio

@godzfire
Copy link

Chrome extension is missing

@Zefferis
Copy link

I think a reasonable way to get round this would be to have the extension figure out the - Share + Start time, and then reload the page with that info, might be more clunky though so it could be an enabled feature that opt-in.

@jidanni
Copy link

jidanni commented Jul 3, 2021

Let's say we watch a movie for a few minutes,
and our eyes get tired.
Alas, this extension seems to only know
about starting again way back at the beginning.

@aljgom
Copy link

aljgom commented Oct 10, 2023

It could be something like this

let savedTime;
let isPaused;

async function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function waitForVideo() {
  let videoElement;
  while (true) {
    videoElement = document.querySelector('video');
    if (videoElement && videoElement.readyState >= 3) {
      break;
    }
    await sleep(500);
  }
  return videoElement;
}

async function saveCurrentTimeAndState() {
  const videoElement = await waitForVideo();
  savedTime = videoElement.currentTime;
  isPaused = videoElement.paused;
}

async function restoreCurrentTimeAndState() {
  const videoElement = await waitForVideo();
  videoElement.currentTime = savedTime;
  if (isPaused) {
    videoElement.pause();
  } else {
    videoElement.play();
  }
}

// To save the current time and state before reloading the page
await saveCurrentTimeAndState();

// To restore the saved time and state after reloading the page
await restoreCurrentTimeAndState();

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

5 participants