Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new event listener which returns the current duration as the audio progresses. #145

Open
khushal87 opened this issue May 19, 2022 · 3 comments

Comments

@khushal87
Copy link

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.

@brunoleitem
Copy link

Can you show your logic with setInterval?

@Yeonbin
Copy link

Yeonbin commented Nov 21, 2022

I want to how to do that! Please share your code..
I need the way how to make progress bar...

@Jobjeuh
Copy link

Jobjeuh commented Oct 12, 2023

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]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants