在野生动物园浏览器中不会播放歌曲。用户单击按钮,音乐就必须播放。在其他浏览器中,一切正常。出现错误
constructor(props) {
super(props);
this.audio = createRef();
}
setActiveState = activeState => {
setTimeout(() => {
this.setState({ activeState }, () => {
this.props.toggleMenu(true);
if (activeState === 2 && this.audio.current.paused) {
setTimeout(() => {
this.audio.current.volume = 0.3;
this.audio.current.play();
this.setEndState();
}, 1700);
}
});
}, 300);
};
<audio
src="/static/files/smart-media.mp3"
ref={this.audio}
loop
preload="metadata"
type="audio/mpeg"
/>