我正在尝试播放webrtc DEMO引用的getUserMedia音频示例。
它可在所有浏览器上运行,但不适用于Mac OS的 Safari 11.1 。有趣的是,它可以在iPad的Safari上运行。
var tempStream;
// Put variables in global scope to make them available to the browser console.
const audio = document.querySelector('audio');
const constraints = window.constraints = {
audio: true,
video: true
};
function handleSuccess(stream) {
const audioTracks = stream.getAudioTracks();
tempStream = stream; // make variable available to browser console
}
function audioPlay() {
audio.srcObject = tempStream;
audio.play();
}
document.querySelector('#audioPlay').addEventListener('click', audioPlay);
navigator.mediaDevices.getUserMedia(constraints).then(handleSuccess);
<div id="container">
<audio id="gum-local" controls></audio> <br />
<button id="audioPlay"> <b> PLAY AUDIO </b> </button>
</div>