【问题标题】:How can i check if an audio is empty?如何检查音频是否为空?
【发布时间】:2021-07-15 01:44:01
【问题描述】:
const radio = new Audio('http://myradiostation.com/stream');

有没有办法知道radio 是否为空(没有声音/音频)?

有时电台主持人忘记打开直播,我想在发生这种情况时给最终用户一些反馈。类似于alert,上面写着“电台主持人忘记打开直播!!!”

我想要实现的是这样的:

if(radio.isEmpty){
    alert('The radio host forgot to turn on the stream!!!')
}else{
    radio.play()
}

提前致谢。

【问题讨论】:

    标签: javascript http httpresponse html5-audio audio-streaming


    【解决方案1】:

    以下方法成功了:

     const radio = new Audio('http://myradiostation.com/stream');
    
      radio
        .play()
        .then(() => {
          console.log('success');
        })
        .catch((error) => {
          console.log(error);
          alert('The radio host forgot to turn on the stream!!!');
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 2019-07-03
      • 2012-07-27
      相关资源
      最近更新 更多