Skip to content

Commit

Permalink
Add an example and restrict audio source to be micrphone.
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjunz committed Jun 28, 2024
1 parent 298c998 commit 35afdfa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ platform UI or media keys, thereby improving the user experience.
<p>
A user agent MUST invoke {{MediaSessionActionHandler}} for
{{MediaSessionAction/voiceactivity}} only when the voice activity is
detected from a source with one or more live {{MediaStreamTrack}}s. A user
agent MAY ignore a {{MediaSessionAction/voiceactivity}} action if all
detected from a microphone with one or more live {{MediaStreamTrack}}s. A
user agent MAY ignore a {{MediaSessionAction/voiceactivity}} action if all
{{MediaStreamTrack}}s associated with the source are not
{{MediaStreamTrack/muted}}. It is RECOMMENDED for user agents to set a
minimal interval for invoking {{MediaSessionActionHandler}} for
Expand Down Expand Up @@ -1825,6 +1825,20 @@ media session</a>.
</pre>
</div>

<div class="example" id="example-enterpictureinpicture">
Handling voice activity:
<pre class="lang-javascript">
// Create a MediaStream with audio enabled.
const stream = await navigator.mediaDevices.getUserMedia({audio:true});
const track = stream.getAudioTracks()[0];
navigator.mediaSession.setActionHandler("voiceactivity", function() {
if (track.muted) {
// Show unmute notification.
}
});
</pre>
</div>

<h2 id="acknowledgments" class="no-num">Acknowledgments</h2>

The editors would like to thank Paul Adenot, Jake Archibald, Tab Atkins,
Expand Down

0 comments on commit 35afdfa

Please sign in to comment.