我从Web服务接收动态inputStream并希望将其插入到HTML5音频标签中以便用户能够播放它,如何动态(以编程方式)设置HTML5标签的内容?
答案 0 :(得分:0)
音频元素能够直接获取流
<h2>Local-Audio</h2>
<audio id="audio1" controls="controls" ></audio>
<button id="btn1" onclick="addStream()">
Add Stream
</button>
<script>
var btn1 = document.getElementById("btn1");
var audio = document.getElementById("audio1");
function addStream() {
getUserMedia({audio : true}, gotStream, function() {});
}
function gotStream(stream) {
audio.src = window.URL.createObjectURL(stream);
audio.play();
}
</script>