📅  最后修改于: 2022-03-11 15:02:14.150000             🧑  作者: Mango
import React from 'react';
import playIcon from './images/play.png';
import pauseIcon from './images/pause.png';
import globalAudio from './globalAudio';
class Music extends React.Component {
constructor(props) {
super(props);
this.state = { 'play': false };
this.name = props.src;
this.togglePlay = this.togglePlay.bind(this);
}
togglePlay() {
this.setState({'play': !this.state.play}, () => {
this.state.play ? globalAudio.play(this.name) : globalAudio.pause(this.name);
});
}
componentWillUnmount () {
globalAudio.pause(this.name);
}
render() {
return (
{this.state.play
?
: }
);
}
}
export default Music;