Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 72ee007

Browse filesBrowse files
committed
figured out how to fix pesky audio bug
1 parent 6436726 commit 72ee007
Copy full SHA for 72ee007

File tree

Expand file treeCollapse file tree

3 files changed

+28
-28
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+28
-28
lines changed
Open diff view settings
Collapse file

‎src/components/overlay.tsx‎

Copy file name to clipboardExpand all lines: src/components/overlay.tsx
+12-23Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22
import { useSpring, animated } from "react-spring";
33
import useStartStore, { StartState } from "../state/start";
44
import * as THREE from "three";
@@ -7,6 +7,7 @@ import { withPrefix } from "gatsby";
77
import { AudioLoader, Camera } from "three";
88
import { useLoader, useThree } from "@react-three/fiber";
99
import { arrayBuffer } from "stream/consumers";
10+
import useSpiralStore from "../state/spiral";
1011

1112
const Overlay = () => {
1213
//const startval = useAppSelector((state) => state.startReducer.startval);
@@ -74,28 +75,16 @@ const Overlay = () => {
7475
);
7576
};
7677
request.send();*/
77-
for (let i = 0; i < 2; i++) {
78-
loader.load(
79-
withPrefix("/home-resonance.wav"),
80-
(buffer) => {
81-
console.log("hi");
82-
console.log(buffer, "test");
83-
audio.setBuffer(buffer);
84-
audio.setLoop(true);
85-
audio.setVolume(0.5);
86-
const analyzer = new THREE.AudioAnalyser(audio, 2048);
87-
audioStore.addAudio(audio, listener, analyzer);
88-
//audio.play();
89-
//audio.pause();
90-
},
91-
(p) => {
92-
console.log(p);
93-
},
94-
(e) => {
95-
console.log(e);
96-
}
97-
);
98-
}
78+
loader.load(withPrefix("/home-resonance.wav"), (buffer) => {
79+
console.log(buffer);
80+
audio.setBuffer(buffer);
81+
audio.setLoop(true);
82+
audio.setVolume(0.5);
83+
const analyzer = new THREE.AudioAnalyser(audio, 2048);
84+
audioStore.addAudio(audio, listener, analyzer);
85+
//audio.play();
86+
//audio.pause();
87+
});
9988

10089
/*
10190
const audioElement = document.querySelector(
Collapse file

‎src/pages/index.tsx‎

Copy file name to clipboardExpand all lines: src/pages/index.tsx
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const IndexPage = () => {
6969
<div id="canvas-container">
7070
<Canvas camera={{ position: [0, 0, -2010], far: 1500 }}>
7171
<CameraControls />
72+
<AudioStarter />
7273
{<color attach="background" args={["black"]} />}
7374
<App />
7475
{/*<ambientLight intensity={0.5} />*/}
@@ -111,7 +112,6 @@ const CameraControls = () => {
111112
const { camera } = useThree();
112113
const startStore = useStartStore();
113114
const spiralStore = useSpiralStore();
114-
const audioStore = useAudioStore();
115115
/*
116116
const bool = useControls({
117117
bool: false,
@@ -131,7 +131,6 @@ const CameraControls = () => {
131131
},
132132
onRest: () => {
133133
if (!spiralStore.done) {
134-
audioStore.play();
135134
spiralStore.notifyDone();
136135
}
137136
},
@@ -143,6 +142,17 @@ const CameraControls = () => {
143142
});
144143
return <OrbitControls enabled={true} maxDistance={750} />;
145144
};
145+
146+
const AudioStarter = () => {
147+
const audioStore = useAudioStore();
148+
const spiralStore = useSpiralStore();
149+
useEffect(() => {
150+
if (audioStore.audio !== null && spiralStore.done) {
151+
audioStore.play();
152+
}
153+
}, [audioStore.audio, spiralStore.done]);
154+
return <></>;
155+
};
146156
function Light() {
147157
const light = useRef<DirectionalLight>(null!);
148158
useHelper(light, DirectionalLightHelper);
Collapse file

‎src/state/spiral.ts‎

Copy file name to clipboardExpand all lines: src/state/spiral.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ type SpiralType = {
77

88
const useSpiralStore = create<SpiralType>((set) => ({
99
done: false,
10-
notifyDone: () =>
11-
set((state) => ({
10+
notifyDone: () => {
11+
return set((state) => ({
1212
...state,
1313
done: true,
14-
})),
14+
}));
15+
},
1516
}));
1617

1718
export default useSpiralStore;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.