之前工作的網頁調用攝像頭獲取視頻並拍照的作品報錯:Failed to execute 'createObjectURL' on 'URL'
原因是Chrome升級後,新版本的Chrome不再支持該用法。其他主流瀏覽器也是如此,
所以原先的代碼:
video.src = URL.createObjectURL(stream);
需要被修改爲
video.srcObject = stream;
一個兼容的寫法如下:
try {
this.srcObject = stream;} catch (error) {
this.src = window.URL.createObjectURL(stream);}