How to play wav audio byte array via javascript/html5?

前端 未结 3 604
小蘑菇
小蘑菇 2020-11-30 05:46

I\'m using the following method to play a byte array containing wav data. The function is being called from a GWT project.

This function plays back sound, but it so

3条回答
  •  难免孤独
    2020-11-30 06:29

    This approach will work with the latest iOS safari comparing to AudioContext. Audio object should be created on tap/click (user interaction) event, so don't do it in request callbacks.

    const audio = new Audio()    
    fetch(url, options) // set content header to array buffer
          .then((response) => {
            var blob = new Blob([response.value], { type: 'audio/mp3' })
            var url = window.URL.createObjectURL(blob)        
            audio.src = url
            audio.play()
          })
    

    snippet from here

提交回复
热议问题