i'm new in react native and have faced to one problem. i'm trying to make a time slider duration of an audio with setInterval(). and when the sound is playing, it will force stop after 1 minute playing the sound with no reason. Then i try to debug with console.log(), when the audio force stop, in the console.log() looks like this:
current time: 01:11
94 current time: 01:14
there is blue dot and it keep running when the audio force stopped
any idea to fix my problem?
this is my play sound function:
const playSound = () => {
try {
if (isPlaying === false) {
sound.play();
setButton(Pause);
setIsPlaying(true);
soundDuration();
}
else if (isPlaying === true) {
sound.pause();
setButton(Play)
setIsPlaying(false)
}
} catch (e) {
console.log('err', e)
}
}
this is my get duration function:
const soundDuration = () => {
setDuration(sound.getDuration())
}
and i use this function to handle the time slider:
useEffect(() => {
var timerID = setInterval(() => loadCurrentTime(), 1000);
return () => clearInterval(timerID);
});
const loadCurrentTime = useCallback(() => {
if (isPlaying) {
sound.getCurrentTime((seconds) => {
console.log('current time: ', convertTime(seconds));
setTimeSlider(seconds);
});
}
}, [sound, isPlaying]);
and this is the Slider:
<Slider
style={{flex: 1, height: 40}}
minimumValue={0}
maximumValue={duration}
minimumTrackTintColor="#FFFFFF"
maximumTrackTintColor="#000000"
thumbTintColor='#f6e3b0'
value={timeSlider}
step={1}
// onValueChange={values => {
// // sound.setCurrentTime(values);
// setTimeSlider(values);
// }}
/>