mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
```text
refactor: Update animation frame handling in artplayer-proxy-webav The code changes replace the use of `requestAnimationFrame` with `setInterval` in the `start` function of `artplayer-proxy-webav`. This change improves the performance and stability of the animation frame handling, ensuring a smoother playback experience.
This commit is contained in:
1 parent
0374046606
commit
984755b442
3 files changed
+15
-16
No files matched your search
@@ -12,7 +12,7 @@ export default function artplayerProxyWebAV() {
|
||||
|
||||
let clip = null;
|
||||
let audioSource = null;
|
||||
let animationFrameId = null;
|
||||
let intervalId = null;
|
||||
let seekTarget = null;
|
||||
let lastSeekTime = 0;
|
||||
|
||||
@@ -51,9 +51,9 @@ export default function artplayerProxyWebAV() {
|
||||
}
|
||||
|
||||
function stop() {
|
||||
if (animationFrameId) {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
animationFrameId = null;
|
||||
if (intervalId) {
|
||||
clearInterval(intervalId);
|
||||
intervalId = null;
|
||||
}
|
||||
if (audioSource) {
|
||||
audioSource.stop();
|
||||
@@ -83,9 +83,10 @@ export default function artplayerProxyWebAV() {
|
||||
stop();
|
||||
updateVolume();
|
||||
|
||||
async function frameHandler(currentFrameTime) {
|
||||
async function frameHandler() {
|
||||
if (!state.playing) return;
|
||||
|
||||
const currentFrameTime = performance.now();
|
||||
const deltaTime = currentFrameTime - lastFrameTime;
|
||||
lastFrameTime = currentFrameTime;
|
||||
|
||||
@@ -132,13 +133,11 @@ export default function artplayerProxyWebAV() {
|
||||
audioSource.start(startAt);
|
||||
startAt += buf.duration / state.playbackRate;
|
||||
}
|
||||
|
||||
animationFrameId = requestAnimationFrame(frameHandler);
|
||||
}
|
||||
|
||||
state.playing = true;
|
||||
state.paused = false;
|
||||
animationFrameId = requestAnimationFrame(frameHandler);
|
||||
intervalId = setInterval(frameHandler, 1000 / 60); // 约60fps
|
||||
}
|
||||
|
||||
async function preview(time) {
|
||||
|
||||
Reference in new issue
Block a user