MediaTrackSupportedConstraints: suppressLocalAudioPlayback property
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Thuộc tính suppressLocalAudioPlayback của từ điển MediaTrackSupportedConstraints cho biết ràng buộc suppressLocalAudioPlayback có được user agent và thiết bị nơi nội dung đang được sử dụng hỗ trợ hay không.
Danh sách các ràng buộc được hỗ trợ được lấy bằng cách gọi navigator.mediaDevices.getSupportedConstraints().
Giá trị
Giá trị boolean là true nếu ràng buộc suppressLocalAudioPlayback được thiết bị và user agent hỗ trợ.
Ví dụ
Hàm dưới đây thiết lập các tùy chọn cho lệnh gọi getDisplayMedia(). Nó thêm ràng buộc suppressLocalAudioPlayback (yêu cầu âm thanh được chụp không phát ra loa cục bộ của người dùng) chỉ khi được biết là được hỗ trợ bởi trình duyệt. Sau đó bắt đầu chụp bằng cách gọi getDisplayMedia() và gắn luồng được trả về vào phần tử video được tham chiếu bởi biến videoElem.
async function capture() {
const supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
const displayMediaOptions = {
audio: {},
};
if (supportedConstraints.suppressLocalAudioPlayback) {
displayMediaOptions.audio.suppressLocalAudioPlayback = true;
}
try {
videoElem.srcObject =
await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
} catch (err) {
/* xử lý lỗi */
}
}
Thông số kỹ thuật
| Specification |
|---|
| Screen Capture> # dom-mediatrackconstraintset-suppresslocalaudioplayback> |