将lambdaj与String.matches方法一起使用(Using lambdaj with String.matches method)
如何使用lambdaj和String.matches方法过滤
Collection<String>
。
我是lambdaj的新手并且感到愚蠢,因为给出的例子比这更复杂。How to filter a
Collection<String>
using lambdaj and the String.matches method.
I'm new to lambdaj and feeling dumb since the examples given are more complicated than this.
原文:https://stackoverflow.com/questions/10044274
最满意答案
等待
loadedmetadata
事件:navigator.mediaDevices.getUserMedia({video: true}) .then(stream => video.srcObject = stream) .then(() => new Promise(resolve => video.onloadedmetadata = resolve)) .then(() => canvas.getContext('2d').drawImage(video, 0, 0, 160, 120)) .catch(e => console.log(e));
<video id="video" width="160" height="120" autoplay></video> <canvas id="canvas" width="160" height="120"></canvas>
以上应该适用于所有浏览器(WebRTC)。
在Chrome中你也可以这样做 - 但是
play()
在任何其他浏览器中都没有返回承诺。另请注意,不推荐使用
URL.createObjectURL(stream)
。 使用srcObject
。Wait for the
loadedmetadata
event:navigator.mediaDevices.getUserMedia({video: true}) .then(stream => { video.srcObject = stream; return new Promise(resolve => video.onloadedmetadata = resolve); }) .then(() => canvas.getContext('2d').drawImage(video, 0, 0, 160, 120)) .catch(e => console.log(e));
<video id="video" width="160" height="120" autoplay></video> <canvas id="canvas" width="160" height="120"></canvas>
The above should work in all browsers (that do WebRTC).
In Chrome you can also do this - but
play()
doesn't return a promise in any other browser yet.Also note that
URL.createObjectURL(stream)
is deprecated. UsesrcObject
.Update: Thanks to @KyleMcDonald in comments for pointing out the importance of registering the
loadedmetadata
listener synchronously with setting thesrcObject
!—Code updated.
相关问答
更多-
getUserMedia错误:NotFoundError 当用户拒绝权限或媒体不可用时,将发生此错误。 在UWP应用程序中,当您要访问媒体捕获时,您需要打开项目的清单文件,转到Capabilities标签并选择Webcam功能以启用应用程序的相机设备。 这将解决问题,但对于您的情况,我认为您可能还需要以相同的方式启用Microphone功能。 getUserMedia error: NotFoundError This error will occurre when the user denies perm ...
-
在getUserMedia上,成功回调的内容是媒体跟踪对象。 您可以在此处查看MediaTrack中提供的所有属性: https : //developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack 要进一步探索质量,您可能必须阅读成功回调流并进行一些自定义检查。 on getUserMedia, what you are getting on success call back is a media track object. You can see ...
-
您可以/必须使用Promise ,例如: var requestDevices = { media:function() { return new Promise(function(resolve, reject) { navigator.getUserMedia({ video: true, audio: true }, resolve, reject); }); } }; var stream = requestDevices.media(); 无论您何 ...
-
这适用于我: Gecko.Xpcom.Initialize(@"******************"); GeckoPreferences.User["plugin.state.flash"] = true; GeckoPreferences.User["browser.xul.error_pages.enabled"] = true; GeckoPreferences.User["media.navigator.enabled"] = true; /* The following line is the ...
-
getUserMedia错误webRTC(getUserMedia Error webRTC)[2021-07-03]
我猜测上面的代码放在一个html文件中并通过单击文件直接访问(和url就像file:///... ),这种方式可以在firefox中工作,但不能在chrome中工作 ,用于相机捕获要处理chrome,您需要在某些服务器上托管该文件。 另外,在不相关的说明中,您可以替换 video.onloadedmetadata =function(e){ video.play(); } 简单地说 video.play(); i am guessing that the code ... -
试试这个: function getUserMedia() { var constraints = { video: true, audio: true }; var deferred = jQuery.Deferred(); if (location.protocol !== "https:") { alert('WARNING: Add https:// before the current url to capture video through WebC ...
-
你提到的第二个演示( 这一个 )适用于Chrome 28上的我。 这听起来像你启用了标志,但要确保在chrome://flags启用了Enable screen capture support in getUserMedia()并且启用Chrome后启动了Chrome)。 The second demo you mentioned (this one) works for me on Chrome 28. It sounds like you enabled the flag, but make sure ...
-
Flash或Java可能会在IE和Safari上完成这项工作。 您需要一个适用于移动设备的本机应用程序。 I have find this API, and she is nice : scriptcam
-
我有同样的问题,我通过调用视频元素上的播放方法来修复它。 即使您添加了autoplay属性,它也无法正常工作。 我最好的猜测是,在加载视频标签时,源是空的,因此无法启动。 navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia; var success = function(stream){ var video = document.getElementById('myVide ...
-
等待loadedmetadata事件: navigator.mediaDevices.getUserMedia({video: true}) .then(stream => video.srcObject = stream) .then(() => new Promise(resolve => video.onloadedmetadata = resolve)) .then(() => canvas.getContext('2d').drawImage(video, 0, 0, 160, ...