我正在使用react-native-sound 模块,但当我开始播放声音并按下
当我重新加载应用程序时,它会再次启动声音,我无法使用
我该如何停止它?
Home
按钮退出应用程序时,声音仍在播放。当我重新加载应用程序时,它会再次启动声音,我无法使用
.stop()
将其销毁,因为它只会销毁第二个加载在第一个声音上方的声音。我该如何停止它?
class Home extends Component {
constructor(props) {
super(props);
this.props.actions.fetchScores();
}
componentWillReceiveProps(nextProps){
nextProps.music.backgroundMusic.stop()
setInterval( () => {
nextProps.music.backgroundMusic.play()
nextProps.music.backgroundMusic.setNumberOfLoops(-1)
}, 1000);
}
}
export default connect(store => ({
music: store.music
})
)(Home);
onPause()
、onStop()
或onDestroy()
方法中调用yourSound.stop()
。 - OpiatefuchscomponentWillReceiveProps()
函数中使用mySound.play()
进行调用。当重新加载应用程序时,它会在之前的背景音乐上再次开始另一首背景音乐。stop()
函数不再起作用,好像无法检测到它。这就是为什么我试图避免在退出应用程序时恢复歌曲的原因。 - Sinan Samet