Skip to content

Commit

Permalink
Added getUserMedia HD demo
Browse files Browse the repository at this point in the history
  • Loading branch information
samdutton committed May 3, 2017
1 parent 5c89ccb commit 3141dcd
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
77 changes: 77 additions & 0 deletions getusermedia/hd/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>

<!--
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html lang="en">
<head>

<meta name="description" content="Simplest possible examples of HTML, CSS and JavaScript." />
<meta name="author" content="//samdutton.com">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<meta itemprop="name" content="simpl.info: simplest possible examples of HTML, CSS and JavaScript">
<meta itemprop="image" content="/images/icons/icon192.png">
<meta name="mobile-web-app-capable" content="yes">
<meta id="theme-color" name="theme-color" content="#fff">

<base target="_blank">

<title>getUserMedia: HD</title>

<link rel="stylesheet" href="../../css/main.css" />

<style>
video {
object-fit: cover;
}

@media (min-width: 1000px) {
video {
height: 480px;
}
}
</style>

</head>

<body>

<div id="container">

<h1><a href="../index.html" title="simpl.info home page">simpl.info</a> getUserMedia: HD</h1>

<div id="highlight">
<p>New codelab: <a href="https://codelabs.developers.google.com/codelabs/webrtc-web">Realtime communication with WebRTC</a></p>
</div>

<video autoplay></video>

<p>The <code>MediaStream</code> object <code>stream</code> passed to the <code>getUserMedia()</code> callback in this demo is in global scope, so you can inspect it from the console.</p>

<p>This demo attempts to get video with a resolution of 1920x1080px.</p>

<p>For more information, see <a href="https://www.html5rocks.com/en/tutorials/getusermedia/intro/" title="Media capture article by Eric Bidelman on HTML5 Rocks">Capturing Audio &amp; Video in HTML5</a> on HTML5 Rocks.</p>

<a href="https://github.com/samdutton/simpl/blob/gh-pages/getusermedia" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>

</div>

<script src="js/main.js"></script>

<script src="../../js/lib/ga.js"></script>

</body>
</html>
35 changes: 35 additions & 0 deletions getusermedia/hd/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

var constraints = {
video: {width: {exact: 1920}, height: {exact: 1080}}
};

var video = document.querySelector('video');

function handleSuccess(stream) {
window.stream = stream; // stream available to console
video.src = window.URL.createObjectURL(stream);
}

function handleError(error) {
console.log('navigator.getUserMedia error: ', error);
}

navigator.mediaDevices.getUserMedia(constraints).
then(handleSuccess).catch(handleError);

0 comments on commit 3141dcd

Please sign in to comment.