可以使用window.URL.createObjectURL()从类似下面的代码中获取URL.
navigator.getUserMedia({ video: true,audio: true },function (localMediaStream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(localMediaStream); video.onloadedMetadata = function (e) { // Do something with the video here. }; },function (err) { console.log("The following error occured: " + err); } );
问题是现在我有一个blob URL,如:
blob:http%3A//localhost%3A1560/f43bed15-da6c-4ff1-b73c-5640ed94e8ee
有没有办法为此创建Media Stream对象?
解决方法
如果您使用angular2,您可以使用platform-browser-package中提供的DOMSanitizer:
import { DomSanitizer } from '@angular/platform-browser'; constructor( private sanitizer: DomSanitizer) { }
然后使用您的流,如下所示:
//your code comes here... video.src = this.sanitizer.bypassSecurityTrustUrl(window.URL.createObjectURL(stream));
这应该只