问题
W3C http://www.w3.org/TR/mediacapture-streams/#life-cycle-and-media-flow article on media flow lifecycle says:
When all tracks connected to a source are muted or disabled, the "on-air" or "recording" indicator for that source can be turned off; when the track is no longer muted or disabled, it must be turned back on.
Is mentioned behaviour implemented in Chrome or not?
回答1:
Update: Firefox now supports turning off the camera light on mute. Edits in bold.
I gather from the subject that you know the answer is no.
Neither Chrome nor Firefox turn off the camera light while a site (temporarily) disables a camera stream. The spec says "can" for turning it off, but "MUST" for turning it back on, so both browsers are in compliance.
You can try it here:
var start = () => navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => video.srcObject = stream)
.catch(e => log(e.name));
toggle.onclick = () => {
var track = video.srcObject && video.srcObject.getVideoTracks()[0];
if (!track) return;
toggle.innerHTML = (track.enabled = !track.enabled) ? "Disable" : "Enable";
}
var log = msg => div.innerHTML += "<p>" + msg + "</p>";
<video id="video" height="120" width="160" autoplay></video><br>
<button onclick="start()">Start!</button>
<button id="toggle">Disable</button><div id="div"></div>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
Note: In Chrome use https://jsfiddle.net/jib1/b6tyjm4s/ instead (getUserMedia + snippets != <3).
As to why, the spec also says:
When permission is not stored, permission should last only until such time as all MediaStreamTracks sourced from that device have been stopped.
This is observable from the camera light as well as in-browser camera & microphone live indicators. For non-persistent permissions, both browsers guarantee users that a site's access ends when the camera light goes off. Turning off the light while a site temporarily disables a stream would break this guarantee. In-browser indicators may buttress this problem.
I'd have to speculate when it comes to https
in Chrome, but at least for Firefox, where permission grants are non-persistent by default, this is why.
来源:https://stackoverflow.com/questions/33304281/why-when-both-audio-and-video-mediastreamtracks-enabled-parameter-set-to-false