CaptureController: increaseZoomLevel() 方法
CaptureController
接口的 increaseZoomLevel()
方法将捕获的显示表面缩放级别增加一个级别。
increaseZoomLevel()
方法必须通过 瞬时激活 调用。此外,用户在首次尝试屏幕捕获时会被请求共享标签页的权限;如果用户拒绝权限,即使有瞬时激活,缩放级别也无法更改。
语法
js
increaseZoomLevel()
参数
无。
返回值
异常
InvalidStateError
DOMException
-
抛出时
- 捕获的显示表面已达到其支持的最大缩放级别。
- 尝试在没有瞬时激活的情况下调用
increaseZoomLevel()
。
NotAllowedError
DOMException
-
抛出时
- 页面的
captured-surface-control
权限策略不允许页面使用 Captured Surface Control API。 - 用户明确拒绝了捕获显示图面的权限。
- 页面的
示例
increaseZoomLevel()
的基本用法
以下代码片段向按钮添加了一个事件监听器,以便在点击按钮时调用 increaseZoom()
函数。该函数接着调用 increaseZoomLevel()
方法,从而放大捕获的表面。
js
// Create controller and start capture
const controller = new CaptureController();
videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia({
controller,
});
// ...
incBtn.addEventListener("click", increaseZoom);
async function increaseZoom() {
try {
await controller.increaseZoomLevel();
} catch (e) {
console.log(e);
}
}
通常,最好将 increaseZoomLevel()
调用放在 try...catch
块中,因为缩放级别可能被应用程序以外的实体异步更改,这可能导致抛出错误。例如,用户可能直接与捕获的表面进行交互来进行缩放。
有关完整的可运行示例,请参阅 使用 Captured Surface Control API。
规范
规范 |
---|
Captured Surface Control # dom-capturecontroller-increasezoomlevel |
浏览器兼容性
加载中…