admin管理员组文章数量:1289581
In a Google's WebRTC tutorial, it has the following example code.
I have two questions for it:
- Why do we need to set window.stream to stream? (What does "stream available to console" mean?)
- If we need to create a URL for stream, why can we set video.src to stream which should be a blob?
Thanks.
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
}
In a Google's WebRTC tutorial, it has the following example code.
I have two questions for it:
- Why do we need to set window.stream to stream? (What does "stream available to console" mean?)
- If we need to create a URL for stream, why can we set video.src to stream which should be a blob?
Thanks.
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
}
Share
Improve this question
edited Aug 23, 2016 at 3:03
Chiu
asked Aug 23, 2016 at 2:45
ChiuChiu
3504 silver badges14 bronze badges
5
-
1
it's setting a globally accessible variable called stream - you could call it
fred
- it doesn't matter - it's just for global access – Jaromanda X Commented Aug 23, 2016 at 2:50 - Thanks!! How about the second question? Can you enlighten me for this one please? – Chiu Commented Aug 23, 2016 at 2:53
- If I had answers I'd post answers - hence why I only posted a ment, as I only knew the simple half of your two questions :p – Jaromanda X Commented Aug 23, 2016 at 2:54
-
1
The second question is for cross-browser support: Chrome uses the
createObjectURL()
function and Firefox can use just the steam by itself. Source: "Chrome uses the createObjectURL method whereas Firefox and Opera send the stream directly" – Samuel Méndez Commented Aug 23, 2016 at 6:06 -
1
@SamuelMéndez Unfortunately, the code is wrong. Luckily the
else
clause never executes in practice. See my answer. – jib Commented Aug 25, 2016 at 4:21
1 Answer
Reset to default 11Old and wrong code. video.src = stream
is wrong. It should be video.srcObject = stream
. It just never runs because all browsers today support URL
.
Instead, use srcObject
whenever available (supported in both Chrome and Firefox) for better life time handling by browsers:
if (typeof video.srcObject == "object") {
video.srcObject = stream;
} else {
video.src = URL.createObjectURL(stream);
}
Or use adapter.js and don't worry about it:
video.srcObject = stream;
Oh, and window.stream
is just some global variable. Likely used for debugging by the sample author.
2013 is old for WebRTC code. I remend looking at the official WebRTC samples instead.
本文标签:
版权声明:本文标题:javascript - If we need to create a URL for stream, why can we set video.src to stream for WebRTC? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741396970a2376437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论