only render milkdrop when playing

This commit is contained in:
jberg 2018-05-15 14:12:11 -07:00 committed by Jordan Eldredge
parent 3418e159db
commit 359c7d25ee

View file

@ -1,4 +1,5 @@
import React from "react";
import { connect } from "react-redux";
import screenfull from "screenfull";
const PRESET_TRANSITION_SECONDS = 2.7;
@ -27,7 +28,14 @@ class MilkdropWindow extends React.Component {
);
this.visualizer.connectAudio(analyserNode);
this.visualizer.loadPreset(reactionDiffusion2, 0);
this._renderViz();
// Kick off the animation loop
const loop = () => {
if (this.props.status === "PLAYING") {
this.visualizer.render();
}
window.requestAnimationFrame(loop);
};
loop();
},
e => {
console.error("Error loading Butterchurn", e);
@ -68,10 +76,6 @@ class MilkdropWindow extends React.Component {
this._setRendererSize(this.props.width, this.props.height);
}
}
_renderViz() {
this.animationFrameRequest = requestAnimationFrame(() => this._renderViz());
this.visualizer.render();
}
_pauseViz() {
if (this.animationFrameRequest) {
window.cancelAnimationFrame(this.animationFrameRequest);
@ -125,4 +129,8 @@ class MilkdropWindow extends React.Component {
}
}
export default MilkdropWindow;
const mapStateToProps = state => ({
status: state.media.status
});
export default connect(mapStateToProps)(MilkdropWindow);