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

Audio: Ensure progress is reset in onEnded(). #29930

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

Jian-Nam
Copy link
Contributor

Issue Description:

The play method of the audio object in Three.js sets the starting point based on the current progress. The progress is updated only when the pause or stop methods are called.

Currently, when pause is executed during playback, the progress is set to the pause point. If the audio is played to the end from that point, the onEnded event is triggered, and the audio stops. However, if playback is restarted after this, the onEnded event does not update the progress. As a result, the audio restarts from the previous pause point rather than the actual start of the audio.

Proposed Solution:

This behavior is unintuitive and can lead to unexpected behavior. To resolve this issue, I modified the onEnded method to execute the stop method, which ensures that progress is updated correctly.

ScreenShot

before

before.mp4

after

after.mp4

Copy link

github-actions bot commented Nov 20, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.13
79
339.13
79
+0 B
+0 B
WebGPU 478.76
132.73
478.76
132.73
+0 B
+0 B
WebGPU Nodes 478.23
132.61
478.23
132.61
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.59
111.96
464.59
111.96
+0 B
+0 B
WebGPU 546.92
148.18
546.92
148.18
+0 B
+0 B
WebGPU Nodes 502.8
137.9
502.8
137.9
+0 B
+0 B

src/audio/Audio.js Outdated Show resolved Hide resolved
@Jian-Nam Jian-Nam changed the title fix: Ensure progress is reset on onEnded by calling stop fix: Ensure progress is reset on onEnded Nov 20, 2024
@Jian-Nam Jian-Nam changed the title fix: Ensure progress is reset on onEnded fix: Ensure audio progress is reset on onEnded Nov 20, 2024
@Mugen87 Mugen87 changed the title fix: Ensure audio progress is reset on onEnded Audio: Ensure progress is reset in onEnded(). Nov 21, 2024
@Mugen87 Mugen87 added this to the r171 milestone Nov 21, 2024
@Mugen87 Mugen87 merged commit dce25de into mrdoob:dev Nov 21, 2024
12 checks passed
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