如何在java </audio>中的HTML5 <audio>标签中动态加载inputStream

时间:2013-06-05 11:39:46

标签: java html5 inputstream audio-streaming html5-audio

我从Web服务接收动态inputStream并希望将其插入到HTML5音频标签中以便用户能够播放它,如何动态(以编程方式)设置HTML5标签的内容?

1 个答案:

答案 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>