This is my code
const [isPlaying, setIsPlaying] = useState(false);
const [playbackObject, setPlaybackObject] = useState(null as any);
const [playbackStatus, setPlaybackStatus] = useState(null as any);
const handleAudioPlayPause = async () => {
try {
if (playbackObject !== null && playbackStatus === null) {
const status = await playbackObject.loadAsync(
{ uri: audioUri },
{ shouldPlay: true }
);
setIsPlaying(true);
return setPlaybackStatus(status);
}
// // It will pause our audio
if (playbackStatus.isPlaying) {
const status = await playbackObject.pauseAsync();
setIsPlaying(false);
return setPlaybackStatus(status);
}
// It will resume our audio
if (!playbackStatus.isPlaying) {
const status = await playbackObject.playAsync();
setIsPlaying(true);
return setPlaybackStatus(status);
}
} catch (error) {
console.log('error in play/pause ', error);
}
};
the playAsync works fine, and playbackStatus.isPlaying change to true, but when pauseAsync() is executed it throws the following error:
[Error: Encountered an error while setting status!]
I was looking in the documentation and in different forums without a solution yet, I even used the same example and it gives me the same error