react-native-sound-player
react-native-sound-player copied to clipboard
Add new event listener which returns the current duration as the audio progresses.
Describe the bug
Hey @johnsonsu
This issue isn't a bug but a feature request where an event can be added if possible in which the callback can return the values of the current duration of the video. This will improve the package usage significantly as currently, you need to add a setInterval logic to update the audio duration in the slider.
To Reproduce
Expected behavior A clear and concise description of what you expected to happen.
Platform (please complete the following information):
- iOS
- Android
Additional context Add any other context about the problem here.
Can you show your logic with setInterval?
I want to how to do that! Please share your code.. I need the way how to make progress bar...
Here is how I did it:
useEffect(() => {
SoundPlayer.loadUrl(attributes.src);
const getDuration = async () => {
const info = await SoundPlayer.getInfo();
setDuration(info.duration);
};
if (Platform.OS === 'ios') {
getDuration();
}
const loadUrlEvent = SoundPlayer.addEventListener('FinishedLoadingURL', ({success}) => {
if (success && Platform.OS !== 'ios') {
getDuration();
}
});
const timeInterval = setInterval(async () => {
const info = await SoundPlayer.getInfo();
setTime(info.currentTime);
}, 1000);
return () => {
loadUrlEvent.remove();
clearInterval(timeInterval);
};
}, [attributes.src]);