Web Audio Api: Proper way to play data chunks from a nodejs server via socket

前端 未结 2 1249
孤独总比滥情好
孤独总比滥情好 2021-01-03 10:03

I\'m using the following code to decode audio chunks from nodejs\'s socket

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var contex         


        
2条回答
  •  粉色の甜心
    2021-01-03 10:54

    yes @Keyne is right,

    const mediaSource = new MediaSource()
    const sourceBuffer = mediaSource.addSourceBuffer('audio/mpeg')
    player.src = URL.createObjectURL(mediaSource)
    sourceBuffer.appendBuffer(chunk) // Repeat this for each chunk as ArrayBuffer
    player.play()
    

    But do this only if you don't care about IOS support

提交回复
热议问题