Skip to content

Commit 1e873df

Browse files
committed
dont call change handlers if player is not defined
1 parent 4e922a2 commit 1e873df

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

examples/simpleExample.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default class SimpleExample extends React.Component {
99
videoId="bQQVybyIk5E"
1010
width="560"
1111
height="315"
12-
onVolumeChange={(v) => console.log(v)}
1312
></YouTubeVideo>
1413
</div>
1514
)

src/YouTubeVideo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class YouTubeVideo extends Component {
3131
return this.player.getCurrentTime() * 1000;
3232
}
3333

34-
startVideoStateObserver = (t) => {
34+
callChangeHandlers() {
3535
const currentPosition = this.getCurrentTimeInMs();
3636
const currentVolume = this.player.isMuted() ? 0 : this.player.getVolume();
3737
if (this.lastSentVolume != currentVolume) {
@@ -42,6 +42,10 @@ export default class YouTubeVideo extends Component {
4242
this.lastSentPosition = currentPosition;
4343
this.props.onProgress(currentPosition);
4444
}
45+
}
46+
47+
startVideoStateObserver = (t) => {
48+
if (this.player) this.callChangeHandlers();
4549
window.requestAnimationFrame(this.startVideoStateObserver);
4650
}
4751

@@ -152,7 +156,7 @@ export default class YouTubeVideo extends Component {
152156
}
153157
}
154158

155-
if (!isNaN(this.props.volume) && prevProps.volume !== this.props.volume) {
159+
if (prevProps.volume !== this.props.volume) {
156160
this.setPlayerVolume(this.props.volume);
157161
}
158162

0 commit comments

Comments
 (0)