CaptureController: phương thức decreaseZoomLevel()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Phương thức decreaseZoomLevel() của giao diện CaptureController giảm mức thu phóng của bề mặt hiển thị đang được chụp xuống một nấc.

Phương thức decreaseZoomLevel() phải được gọi thông qua kích hoạt tạm thời. Ngoài ra, người dùng sẽ được hỏi quyền chia sẻ tab khi lần đầu cố gắng chụp màn hình; nếu người dùng từ chối cấp quyền thì mức thu phóng sẽ không thể thay đổi ngay cả khi có kích hoạt tạm thời.

Syntax

js
decreaseZoomLevel()

Parameters

Không có.

Return value

Một Promise hoàn tất với undefined.

Exceptions

InvalidStateError DOMException

Được ném ra khi:

  • Bề mặt hiển thị đang được chụp đã ở mức thu phóng tối thiểu mà nó hỗ trợ.
  • Có một nỗ lực gọi decreaseZoomLevel() mà không có kích hoạt tạm thời.
NotAllowedError DOMException

Được ném ra khi:

Examples

Cách dùng decreaseZoomLevel() cơ bản

Đoạn mã sau thêm một trình lắng nghe sự kiện vào một nút để khi nút được nhấn, hàm decreaseZoom() được gọi. Hàm này sẽ gọi phương thức decreaseZoomLevel(), làm thu nhỏ bề mặt đang được chụp.

js
// Create controller and start capture
const controller = new CaptureController();
videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia({
  controller,
});

// ...

decBtn.addEventListener("click", decreaseZoom);

async function decreaseZoom() {
  try {
    await controller.decreaseZoomLevel();
  } catch (e) {
    console.log(e);
  }
}

Nhìn chung, cách làm tốt nhất là gọi decreaseZoomLevel() bên trong khối try...catch vì mức thu phóng có thể bị thay đổi không đồng bộ bởi một thực thể khác ngoài ứng dụng, điều này có thể dẫn đến ngoại lệ được ném ra. Ví dụ, người dùng có thể tương tác trực tiếp với bề mặt đang được chụp để phóng to hoặc thu nhỏ.

Xem Using the Captured Surface Control API để có ví dụ đầy đủ đang hoạt động.

Specifications

Specification
Captured Surface Control
# dom-capturecontroller-decreasezoomlevel

Browser compatibility

See also