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

fix: enable audio instance reuse, sound no overlap #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RyotaGamePG
Copy link
Collaborator

Audio instances were being created each time, so they can be reused.

To avoid disturbing the tempo of the sound, a new sound with a new character (or speed) is now played after checking for a pause.

Copy link

vercel bot commented Nov 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
phasmo-tracks ❌ Failed (Inspect) Nov 25, 2023 3:36am

@RyotaGamePG RyotaGamePG self-assigned this Nov 25, 2023
Copy link
Owner

@RuiOkazaki RuiOkazaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, I've left a comment! 👍

Comment on lines -51 to -54

// 初回の足音を再生
const footstepsAudio = loadFootstepsAudio();
playAudio(footstepsAudio);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary to keep the initial audio playback, as removing it means the audio will only play after the interval has elapsed

@@ -9,11 +9,15 @@ const loadFootstepsAudio = () => {
return footsteps;
};

//オーディオインスタンス
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//オーディオインスタンス
// オーディオインスタンス

nits: plz add a space before the comments

@@ -9,11 +9,15 @@ const loadFootstepsAudio = () => {
return footsteps;
};

//オーディオインスタンス
const footstepsAudio = loadFootstepsAudio();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since new Audio cannot be accessed on the server, some ingenuity is needed

fyi:
Initialize within the playSounds inside useFootsteps, which is certain to be executed on the client
Alternatively, if you want to persist the audio using useRef, initialize it inside useFootsteps but only when isClient is true

example:

  const footstepsAudio = useRef<HTMLAudioElement>();
  if (isClient && !footstepsAudio.current)
    footstepsAudio.current = loadFootstepsAudio();

const playAudio = (audio: HTMLAudioElement) => {
if (!audio.paused) {
audio.pause();
audio.currentTime = 0; //タイム0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

nits:
plz add a space before the comments

imho:
I prefer to have line breaks in comments, so it's a bit of an issue for me, but either way is fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked locally, and in the case of fast-moving ghosts, the audio is forcibly cut off, causing it to sound interrupted

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

Successfully merging this pull request may close these issues.

2 participants