zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

.resume() is not a function error when calling resume on a Sound object. #610

Open nadav2051 opened 5 years ago

nadav2051 commented 5 years ago

:beetle: Description

calling .resume() produces a 'resume is not a function' error.

:beetle: What is the observed behavior?

A Sound reference has been initialized, a play has been called on that reference, the music has started playing. Once a .resume() has been called on the same reference, RN threw an error of 'resume is not a function'. When switching .resume() to .play() at the exact same location, it's working properly, the only problem is it's playing the song from the beginning. however that negates the possibility I'm working on a null reference in that state.

:beetle: What is the expected behavior?

I expect the sound to resume at the same time I've called the .pause() function.

:beetle: Please post your code:

    onPressReadyToPlayState() {
        this.state.soundReference.play();
        this.setState({
            playStatus: SoundStatusEnum.PLAYING
        });
    }

    onPressPlayingState() {
        this.state.soundReference.stop();
        this.setState({
            playStatus: SoundStatusEnum.PAUSED
        });
        return;
    }

    onPressPausedState() {
        this.state.soundReference.resume();
        this.setState({
            playStatus: SoundStatusEnum.PLAYING
        });
        return;
    }

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

:bulb: If the bug is confirmed, would you be willing to create a pull request?

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

paulmelnikow commented 5 years ago

Could you post a stack trace?

nadav2051 commented 5 years ago

Sure, I'll reproduce and post it, but I've also noticed that I can't find .resume() in the API representation at the index.d.ts, is it possible it has been deprecated?

paulmelnikow commented 5 years ago

I don't see a .resume() function. I think you just use .play().

nadav2051 commented 4 years ago

Yep, I've worked around by tracking current second while pausing, and seek to position before playing again.

just .play()ing will restart the audio.

Anyway, I'd say the API on the front page should be updated to remove the Resume functionality unless we've both missed something.

meghaptg commented 4 years ago

Yep, I've worked around by tracking current second while pausing, and seek to position before playing again.

just .play()ing will restart the audio.

Anyway, I'd say the API on the front page should be updated to remove the Resume functionality unless we've both missed something.

Hey @nadav2051 may I know what the workaround was?

nadav2051 commented 4 years ago

@meghaptg Sure!

One you start playing, you set an interval that tracks the seconds played (soundObject.getCurrentTime), keep that data in the object level, and when a time when you want to resume comes, use soundObject.setCurrentTime to the time you have saved from the interval tracking the getCurrentTime, followed by soundObject.play().

Hope you found this helpful!