[英]How can i check if an audio is empty?
const radio = new Audio('http://myradiostation.com/stream');
有沒有辦法知道radio
是否為空(沒有聲音/音頻)?
有時電台主機忘記開啟stream,遇到這種情況我想給終端用戶一些反饋。 類似於“電台主持人忘記打開直播!!!”的alert
。
我想要實現的是這樣的:
if(radio.isEmpty){
alert('The radio host forgot to turn on the stream!!!')
}else{
radio.play()
}
提前致謝。
以下是訣竅:
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!!!');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.