INNER CODE UNIT · JavaScript

play

maester365/maester · website/src/components/PronunciationButton/index.js:61

  const play = useCallback(() => {
    let cached = audioRef.current;

    // The URL is kept with the element so that a caller which swaps `src`
    // does not keep hearing the recording from the previous one.
    if (!cached || cached.url !== audioUrl) {
      cached?.element.pause();

      const element = new Audio(audioUrl);
      element.preload = "none";
      element.addEventListener("ended", () => setIsPlaying(false));
      element.addEventListener("error", () => setIsPlaying(false));

      cached = { url: audioUrl, element };
      audioRef.current = cached;
    }

    cached.element.currentTime = 0;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…