Skip to content

Commit

Permalink
fix mobile devices perf throttled
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Dec 25, 2024
1 parent 591e073 commit 5e4e6ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
8 changes: 1 addition & 7 deletions app/components/control-bar/audio-player/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LegacyRef, SyntheticEvent, use, useEffect, useRef } from "react";
import { SyntheticEvent, useRef } from "react";
import styles from "./styles.module.css"
import useGlobalStore, { Gui } from "@/app/stores/useGlobalStore";
import usePresetStore from "@/app/stores/usePresetStore";
Expand Down Expand Up @@ -49,11 +49,6 @@ function AudioPlayer() {
useGlobalStore.setState({ enabledTransform: true })
}

const onSeeked = (e: SyntheticEvent<HTMLVideoElement, Event>) => {
setTime(ytPlayer.current.currentTime);
useGlobalStore.setState({ enabledTransform: true })
}

const onLoadedMetadata = (e: SyntheticEvent<HTMLVideoElement, Event>) => {
ytPlayer.current.currentTime = currentTime
useGlobalStore.setState({ player: ytPlayer.current })
Expand Down Expand Up @@ -91,7 +86,6 @@ function AudioPlayer() {
src={gui.ytUrl}
onPlay={onPlay}
onPause={onPause}
onSeeked={onSeeked}
onLoadedMetadata={onLoadedMetadata}
></YoutubeVideo>
</MediaTheme>
Expand Down
21 changes: 2 additions & 19 deletions app/components/three-world/renderLoop/useRenderLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ function useRenderLoop() {
}

const currTime = player.currentTime
// player has a bug that sometimes jump to end(duration)
// so we just skip that frame
if (player.currentTime == player.duration) {
return
}

const delta = currTime - prevTimeRef.current;

if (Math.abs(delta) > 0) {
// check if time seeking using player control
if (Math.abs(delta) > 0.1) {
if (Math.abs(delta) > 1.0) {
helper.enable('physics', false);
}

Expand All @@ -41,7 +35,7 @@ function useRenderLoop() {
helper.update(delta, currTime);

// check if time seeking using player control
if (Math.abs(delta) > 0.1) {
if (Math.abs(delta) > 1.0) {
runtimeCharacter.physics.reset();
helper.enable('physics', physics);
}
Expand All @@ -56,17 +50,6 @@ function useRenderLoop() {
runtimeCharacter.physics.update(delta);
}
}

// stop when motion is finished and then fix physics
if (runtimeCharacter.looped) {
player.pause();
player.currentTime = 0.0

runtimeCharacter.physics.reset();
runtimeCharacter.physics.update(0.1)

runtimeCharacter.looped = false;
}
}, 1)
}

Expand Down

0 comments on commit 5e4e6ac

Please sign in to comment.