Update:
I'm leaving this to save research and time for others. I used onPressIn instead of onPress for better results. The events are called as follows. onPressIn --> onPressOut --> onPress
<TouchableWithoutFeedback onPressIn={() => {sound.play()}}>
<View><Text></Text></View>
</TouchableWithoutFeedback>
As the title says, i'm trying to use expo-av for an instrument app where sound should be instantly played on press. I tried preloading the sound and the delay shortened but there was a still about 50ms of lag.
App.js
import { playSound } from "PlaySound";
export default function App() {
const [sound, setSound] = useState({});
useEffect(() => {
const getStateData = async () => {
setSound(await playSound(require(`./assets/Sound/ding.mp3`)));
};
getStateData();
}, []);
return (
<TouchableWithoutFeedback
onPress={() => {
sound.play();
}}
>
<View>
<Text></Text>
</View>
</TouchableWithoutFeedback>
);
}
PlaySound.js
import { Audio } from "expo-av";
export async function playSound(path) {
const audio = await Audio.Sound.createAsync(path);
return {
async play() {
await audio.sound.replayAsync();
},
};
}
Any help to reduce the lag would be appreciated
What's expected is for the sound to be instantaneous and not have any lag.