0
我有一個反應組件,其中包含播放直播的Audio
對象。當組件最初加載它開始播放時,但是,如果我卸載組件然後重新安裝它,播放按鈕不起作用,並且流不會重新啓動。使用React重新安裝音頻對象時不重新啓動流
下面是組件和生命週期方法的代碼:
import React from 'react'
import compose from 'recompose/compose'
import lifecycle from 'recompose/lifecycle'
const enhance = compose(
lifecycle({
componentDidMount() {
this.audio = new Audio()
this.audio.src = 'http://some-stream-url.com'
this.audio.play()
this.audio.muted = true
},
componentDidUpdate() {
this.audio.muted = !this.props.playing
},
componentWillUnmount() {
this.audio = ''
this.audio = null
}
})
)
const Player = (props) => null
export default enhance(Player)
不幸的是,這似乎緩存離線前的最後幾秒,但它不會再次實例化流 –