diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/screen_capture_api/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/screen_capture_api/index.html')
-rw-r--r-- | files/zh-cn/web/api/screen_capture_api/index.html | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/screen_capture_api/index.html b/files/zh-cn/web/api/screen_capture_api/index.html new file mode 100644 index 0000000000..9c7385bf34 --- /dev/null +++ b/files/zh-cn/web/api/screen_capture_api/index.html @@ -0,0 +1,143 @@ +--- +title: 屏幕捕捉API +slug: Web/API/Screen_Capture_API +tags: + - API + - Capture + - Conference + - Media + - MediaDevices + - MediaStream + - NeedsTranslation + - Overview + - Screen Capture + - Screen Capture API + - Screen Sharing + - Sharing + - TopicStub + - Video + - Window + - display + - getDisplayMedia + - screen +translation_of: Web/API/Screen_Capture_API +--- +<div>{{DefaultAPISidebar("屏幕捕获API")}}</div> + +<p><span class="seoSummary">屏幕捕获API对现有的媒体捕获和流API进行了补充,让用户选择一个屏幕或屏幕的一部分(如一个窗口)作为媒体流进行捕获。然后,该流可以被记录或通过网络与他人共享。</span></p> + +<h2 id="屏幕捕捉API的概念和用法">屏幕捕捉API的概念和用法</h2> + +<p>屏幕捕捉API使用起来相对简单。其唯一的方法是{{domxref("MediaDevices.getDisplayMedia()")}},它的任务是以捕获的形式要求用户选择一个屏幕或屏幕的一部分的{{domxref("MediaStream")}}。</p> + +<p>要开始从屏幕上捕捉视频,你需要在 <code>getDisplayMedia()</code> 的实例上调用 <code>Media</code> <code>navigator.mediaDevices</code>:</p> + +<pre class="brush: js notranslate">captureStream = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);</pre> + +<p>The {{jsxref("Promise")}} returned by <code>getDisplayMedia()</code> resolves to a {{domxref("MediaStream")}} which streams the captured media.</p> + +<p>See the article <a href="/zh-CN/docs/Web/API/Screen_Capture_API/%E4%BD%BF%E7%94%A8%E5%B1%8F%E5%B9%95%E6%8D%95%E8%8E%B7API">Using the Screen Capture API</a> for a more in-depth look at how to use the API to capture screen contents as a stream.</p> + +<h2 id="增加现有接口">增加现有接口</h2> + +<p>屏幕捕捉API没有自己的任何接口,而是在现有的 {{domxref("MediaDevices")}} 接口上添加了一个方法。</p> + +<h3 id="MediaDevices_接口">MediaDevices 接口</h3> + +<dl> + <dt>{{domxref("MediaDevices.getDisplayMedia()")}}</dt> + <dd>The <code>getDisplayMedia()</code> method is added to the <code>MediaDevices</code> interface. Similar to {{domxref("MediaDevices.getUserMedia", "getUserMedia()")}}, this method creates a promise that resolves with a {{domxref("MediaStream")}} containing the display area selected by the user, in a format that matches the specified options.</dd> +</dl> + +<h2 id="Additions_to_existing_dictionaries">Additions to existing dictionaries</h2> + +<p>The Screen Capture API adds properties to the following dictionaries defined by other specifications.</p> + +<h3 id="MediaTrackConstraints">MediaTrackConstraints</h3> + +<dl> + <dt>{{domxref("MediaTrackConstraints.cursor")}}</dt> + <dd>A {{domxref("ConstrainDOMString")}} indicating whether or not the cursor should be included in the captured display surface's stream, and if it should always be visible or if it should only be visible while the mouse is in motion.</dd> + <dt>{{domxref("MediaTrackConstraints.displaySurface")}}</dt> + <dd>A {{domxref("ConstrainDOMString")}} indicating what type of display surface is to be captured. The value is one of <code>application</code>, <code>browser</code>, <code>monitor</code>, or <code>window</code>.</dd> + <dt>{{domxref("MediaTrackConstraints.logicalSurface")}}</dt> + <dd>Indicates whether or not the video in the stream represents a logical display surface (that is, one which may not be entirely visible onscreen, or may be completely offscreen). A value of <code>true</code> indicates a logical display surface is to be captured.</dd> +</dl> + +<h3 id="MediaTrackSettings">MediaTrackSettings</h3> + +<dl> + <dt>{{domxref("MediaTrackSettings.cursor")}}</dt> + <dd>A string which indicates whether or not the display surface currently being captured includes the mouse cursor, and if so, whether it's only visible while the mouse is in motion or if it's always visible. The value is one of <code>always</code>, <code>motion</code>, or <code>never</code>.</dd> + <dt>{{domxref("MediaTrackSettings.displaySurface")}}</dt> + <dd>A string indicating what type of display surface is currently being captured. The value is one of <code>application</code>, <code>browser</code>, <code>monitor</code>, or <code>window</code>.</dd> + <dt>{{domxref("MediaTrackSettings.logicalSurface")}}</dt> + <dd>A Boolean value which is <code>true</code> if the video being captured doesn't directly correspond to a single onscreen display area.</dd> +</dl> + +<h3 id="MediaTrackSupportedConstraints">MediaTrackSupportedConstraints</h3> + +<dl> + <dt>{{domxref("MediaTrackSupportedConstraints.cursor")}}</dt> + <dd>A Boolean which is <code>true</code> if the user agent and device support the {{domxref("MediaTrackConstraints.cursor")}} constraint.</dd> + <dt>{{domxref("MediaTrackSupportedConstraints.displaySurface")}}</dt> + <dd>A Boolean which is <code>true</code> if the current environment supports the {{domxref("MediaTrackConstraints.displaySurface")}} constraint.</dd> + <dt>{{domxref("MediaTrackSupportedConstraints.logicalSurface")}}</dt> + <dd>A Boolean which is <code>true</code> if the current environment supports the constraint {{domxref("MediaTrackConstraints.logicalSurface")}}.</dd> +</dl> + +<h2 id="Dictionaries">Dictionaries</h2> + +<p>The following dictionaries are defined by the Screen Capture API.</p> + +<dl> + <dt><code>CursorCaptureConstraint</code></dt> + <dd>An enumerated string type used to provide the value for the <code>cursor</code> property for the settings and constraints. The possible values are <code>always</code>, <code>motion</code>, and <code>never</code>.</dd> + <dt><code>DisplayCaptureSurfaceType</code></dt> + <dd>An enumerated string type which is used to identify the kind of display surface to capture. This type is used for the <code>displaySurface</code> property in the constraints and settings objects, and has the possible values <code>application</code>, <code>browser</code>, <code>monitor</code>, and <code>window</code>.</dd> +</dl> + +<h2 id="Feature_Policy_validation">Feature Policy validation</h2> + +<p>{{Glossary("User agent", "User agents")}} that support Feature Policy (either using HTTP's {{HTTPHeader("Feature-Policy")}} header or the {{HTMLElement("iframe")}} attribute {{htmlattrxref("allow", "iframe")}}) can specify a desire to use the Screen Capture API using the policy control directive <code>display-capture</code>:</p> + +<pre class="brush: html notranslate"><iframe allow="display-capture" src="/some-other-document.html"></pre> + +<p>The default allow list is <code>self</code>, which lets the any content within the document use Screen Capture.</p> + +<p>See <a href="/en-US/docs/Web/HTTP/Feature_Policy/Using_Feature_Policy">Using Feature Policy</a> for a more in-depth explanation of how Feature Policy is used.</p> + +<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>规范</strong></span></font></p> + +<p> + </p><table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">说明</th> + </tr> + <tr> + <td>{{SpecName('Screen Capture')}}</td> + <td>{{Spec2('Screen Capture')}}</td> + <td>初始定义。</td> + </tr> + </tbody> + </table> + + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.MediaDevices.getDisplayMedia")}}</p> +</div> + +<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>相关链接</strong></span></font></p> + +<p> + </p><ul> + <li><a href="/en-US/docs/Web/API/Screen_Capture_API/Using_Screen_Capture">Using the Screen Capture API</a></li> + <li>{{domxref("MediaDevices.getDisplayMedia()")}}</li> + </ul> |