0
The sound plays normally, but the pause doesn’t work. I tried several algorithms and nothing worked. I think it’s something with the Promisses, because I don’t know much about asynchrony. But when I put only the pause function on another button, it works normally. Anything I add that’s not exactly that, it doesn’t work...
const SoundManagement: React.FC = () => {
const [isPlay, setIsPlay] = useState(false);
const currentSound = new Audio.Sound();
useEffect(() => {
loadSound();
}, []);
async function loadSound() {
try {
await currentSound.loadAsync(require('../../../sounds/cogulandia.mp3'));
} catch(err) {
console.log(`Erro ao carregar a música \n ${err}`);
}
}
async function playSound() {
setIsPlay(true);
try {
await currentSound.playAsync();
} catch(err) {
console.log(`Erro ao iniciar a música \n ${err}`);
}
}
async function pauseSound() {
setIsPlay(false);
try {
await currentSound.pauseAsync();
} catch(err) {
console.log(`Erro ao pausar a música \n ${err}`);
}
}
return(
<Container>
<Button onPress={ isPlay ? () => pauseSound() : () => playSound()}>
{isPlay
? <FontAwesome5 name='pause' size={20} color={theme.ruby} />
: <FontAwesome5 name='play' size={20} color={theme.lighter} />
}
</Button>
</Container>
);
}