Skip to content

Commit 8c3459d

Browse files
committedAug 5, 2024·
fix(): fix audio pause on page leave, fix binary background noise
1 parent 26e7cca commit 8c3459d

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed
 

‎next.config.js

-22
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,6 @@ const nextConfig = {
4040
exclude: /node_modules/,
4141
use: ['raw-loader', 'glslify-loader'],
4242
});
43-
config.module.rules.push({
44-
test: /\.module\.scss$/,
45-
use: [
46-
'style-loader',
47-
{
48-
loader: 'css-loader',
49-
options: {
50-
modules: true,
51-
importLoaders: 1,
52-
sourceMap: true,
53-
},
54-
},
55-
'sass-loader',
56-
],
57-
exclude: /node_modules/,
58-
});
59-
60-
config.module.rules.push({
61-
test: /\.scss$/,
62-
use: ['style-loader', 'css-loader', 'sass-loader'],
63-
exclude: /\.module\.scss$/,
64-
});
6543
return config;
6644
},
6745
};
-1.5 MB
Binary file not shown.

‎src/components/Audio/AudioContext.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useState, useMemo, useCallback, useRef } from 'react';
1+
import React, { createContext, useState, useMemo, useCallback, useRef, useEffect } from 'react';
22
import sounds from './AudioManager';
33

44
export const AudioContext = createContext(null);
@@ -114,6 +114,22 @@ export const AudioProvider = ({ children }) => {
114114
updateIsPlaying();
115115
}, [updateIsPlaying]);
116116

117+
useEffect(() => {
118+
const handleVisibilityChange = () => {
119+
if (document.hidden) {
120+
fadeOutAllPlayingSounds();
121+
} else {
122+
fadeInBackgroundMusicAndResumeOthers();
123+
}
124+
};
125+
126+
document.addEventListener('visibilitychange', handleVisibilityChange);
127+
128+
return () => {
129+
document.removeEventListener('visibilitychange', handleVisibilityChange);
130+
};
131+
}, [fadeInBackgroundMusicAndResumeOthers, fadeOutAllPlayingSounds]);
132+
117133
const value = useMemo(
118134
() => ({
119135
isPlaying,

‎src/components/Audio/AudioManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Howl } from 'howler';
22

33
const backgroundMusic = new Howl({
44
src: ['/audio/Explora - Benedict Lang.mp3'],
5-
//loop: true,
6-
volume: 0.007,
5+
loop: true,
6+
volume: 0.006,
77
});
88

99
const click = new Howl({

0 commit comments

Comments
 (0)
Please sign in to comment.