I am using react-native-sound to create an audio player, I want to get the current playback timings of the sound while it plays however when I use the getCurrentTime callback, it is only showing 0. Below is the code for the same:
const listenaudio = (audio, id) => {
console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
if (playAudio != null) {
playAudio.release();
}
setsoundpause(id);
playAudio = new Sound(audio, Sound.MAIN_BUNDLE, (error) => {
console.log("rrr")
if (error) {
return;
}
// loaded successfully
// Play the sound with an onEnd callback
playAudio.play((success) => {
if (success) {
setsoundpause(0);
} else {
}
});
});
playAudio.setVolume(1);
playAudio.getCurrentTime((seconds) => console.log('at ' + seconds)); // here
};
It would be great if anyone could suggest how should I do it? Should I use seInterval() ? Any leads would be appreciated.
I've made a player recently using react-native-sound, where I call getCurrentTime method after some milliseconds to get realtime player time.
My function to play audio