Javascript 使用React重新装载时音频对象未重新启动流

Javascript 使用React重新装载时音频对象未重新启动流,javascript,reactjs,html5-audio,Javascript,Reactjs,Html5 Audio,我有一个react组件,它包含一个音频对象,它是一个正在播放livestream的对象。当组件最初加载时,它开始播放,但是如果我卸载该组件,然后重新安装它,播放按钮将不起作用,流也不会重新启动 以下是组件和生命周期方法的代码: import React from 'react' import compose from 'recompose/compose' import lifecycle from 'recompose/lifecycle' const enhance = compose(

我有一个react组件,它包含一个
音频
对象,它是一个正在播放livestream的对象。当组件最初加载时,它开始播放,但是如果我卸载该组件,然后重新安装它,播放按钮将不起作用,流也不会重新启动

以下是组件和生命周期方法的代码:

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)

停止音频并重新启动当前时间

componentWillUnmount() {
   this.audio.pause()
   this.audio.currentTime = 0
}

不幸的是,这似乎只是缓存脱机前的最后几秒钟,但它不会再次实例化流