编程语言
首页 > 编程语言> > javascript – 如何从Blob网址检索MediaStream?

javascript – 如何从Blob网址检索MediaStream?

作者:互联网

可以使用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

有没有办法从中检索MediaStream对象?

解决方法:

如果您使用angular2,您可以使用platform-b​​rowser-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));

这应该只

标签:javascript,html5-audio,html5-video
来源: https://codeday.me/bug/20191007/1869280.html