mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-24 18:47:44 +00:00
only render milkdrop when playing
This commit is contained in:
parent
3418e159db
commit
359c7d25ee
1 changed files with 14 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue