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

got audio is undefined when componentWillUnmount #28

Closed
JackHuang16 opened this issue Mar 2, 2020 · 5 comments
Closed

got audio is undefined when componentWillUnmount #28

JackHuang16 opened this issue Mar 2, 2020 · 5 comments
Assignees
Labels

Comments

@JackHuang16
Copy link

hi
I got audio variation is undefined when componentWillUnmount.

it happened in CurrentTime.js, Duration.js, ProgressBar.js, and VolumeBar.js when componentWillUnmount

and I change it to this, everything goes fine.

CurrentTime.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if( audio && this.hasAddedAudioEventListener ) {
  audio.removeEventListener('timeupdate', this.handleAudioCurrentTimeChange);
  audio.removeEventListener('loadedmetadata', this.handleAudioCurrentTimeChange);
  this.hasAddedAudioEventListener = false;
}

};
`

Duration.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('durationchange', this.handleAudioDurationChange);
  this.hasAddedAudioEventListener = false;
}

};
`

VolumeBar.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('volumechange', this.handleAudioVolumeChange);
  this.hasAddedAudioEventListener = false;
}
clearTimeout(this.volumeAnimationTimer);

};
`

ProgressBar.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('timeupdate', this.handleAudioTimeUpdate);
  audio.removeEventListener('progress', this.handleAudioDownloadProgressUpdate);
  this.hasAddedAudioEventListener = false;
}

clearTimeout(this.downloadProgressAnimationTimer);

};
`

please check it

Thanks a lot : )

Screen Shot 2020-03-03 at 12 10 49 AM

Screen Shot 2020-03-03 at 12 11 05 AM

Screen Shot 2020-03-03 at 12 12 30 AM

@lhz516
Copy link
Owner

lhz516 commented Mar 2, 2020

Thanks for reporting. Which package version is it? How do you reproduce this exactly?

@JackHuang16
Copy link
Author

My version is ^2.4.1.
I have a search bar for users to input, then call the API to present the result with react-h5-audio-player.
The first time is no problem, but when the user search again, it will crash by that.

Thanks

@lhz516
Copy link
Owner

lhz516 commented Mar 3, 2020

The fix is easy but I can't reproduce that and don't know the root cause.

I just published 2.4.2-beta.0 and 2.4.2-beta.1 using two different ways.

Could you check if both work for you or only the second one works for you? After that I'll publish the formal 2.4.2

@lhz516 lhz516 self-assigned this Mar 3, 2020
@lhz516 lhz516 added the bug label Mar 3, 2020
@JackHuang16
Copy link
Author

only 2.4.2-beta.1 worked fine in my scenario
2.4.2-beta.0 still got the same error
thanks a lot : )

@lhz516
Copy link
Owner

lhz516 commented Mar 4, 2020

Thanks for testing. Published 2.4.2. Closing

@lhz516 lhz516 closed this as completed Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants