parent
9e60fee6ee
commit
34207314f5
@ -0,0 +1,10 @@
|
||||
// store.js
|
||||
import { create } from "zustand";
|
||||
|
||||
const useStore = create((set: any) => ({
|
||||
count: 0,
|
||||
increase: () => set((state: any) => ({ count: state.count + 1 })),
|
||||
decrease: () => set((state: any) => ({ count: state.count - 1 })),
|
||||
}));
|
||||
|
||||
export default useStore;
|
@ -0,0 +1,38 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Audio, InterruptionModeAndroid, InterruptionModeIOS } from "expo-av";
|
||||
|
||||
const useSoundEffect = (soundFile) => {
|
||||
const [sound, setSound] = useState(null); // Explicitly set initial state to null
|
||||
|
||||
useEffect(() => {
|
||||
const loadSound = async () => {
|
||||
// await Audio.setAudioModeAsync({
|
||||
// staysActiveInBackground: true,
|
||||
// shouldDuckAndroid: true,
|
||||
// playThroughEarpieceAndroid: false,
|
||||
// interruptionModeIOS: InterruptionModeIOS.DoNotMix,
|
||||
// interruptionModeAndroid: InterruptionModeAndroid.DoNotMix,
|
||||
// allowsRecordingIOS: false,
|
||||
// playsInSilentModeIOS: true,
|
||||
// });
|
||||
const { sound: newSound } = await Audio.Sound.createAsync(soundFile);
|
||||
setSound(newSound);
|
||||
};
|
||||
|
||||
loadSound();
|
||||
|
||||
return () => {
|
||||
sound?.unloadAsync();
|
||||
};
|
||||
}, [soundFile, sound]); // Include sound in the dependency array
|
||||
|
||||
const playSound = async () => {
|
||||
if (sound) {
|
||||
await sound.playAsync();
|
||||
}
|
||||
};
|
||||
|
||||
return playSound;
|
||||
};
|
||||
|
||||
export default useSoundEffect;
|
Loading…
Reference in new issue