Created
September 18, 2012 17:41
-
-
Save anantn/3744555 to your computer and use it in GitHub Desktop.
navigator.mozGetUserMediaDevices Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <h1>Device Test</h1> | |
| <ul id="contents"> | |
| </ul> | |
| <video id="tehvideo"/> | |
| <audio id="tehaudio"/> | |
| <script> | |
| var devices; | |
| var nav = navigator.QueryInterface(Components.interfaces.nsINavigatorUserMedia); | |
| nav.mozGetUserMediaDevices(function(d) { | |
| devices = d; | |
| for (var i = 0; i < d.length; i++) { | |
| var device = d[i].QueryInterface(Components.interfaces.nsIMediaDevice); | |
| var t = document.createElement("li"); | |
| var inner = device.type + ": "; | |
| inner += "<a href='#' onclick='startIt(" + i + ");'>" + device.name + "</a>"; | |
| t.innerHTML = inner; | |
| document.getElementById("contents").appendChild(t); | |
| }; | |
| }, function(e) { alert("Error! " + e); }); | |
| function startIt(num) { | |
| var output, params; | |
| var d = devices[num].QueryInterface(Components.interfaces.nsIMediaDevice); | |
| if (d.type == "video") { | |
| params = {video:true, device:d}; | |
| output = document.getElementById("tehvideo"); | |
| } else { | |
| params = {audio:true, device:d}; | |
| output = document.getElementById("tehaudio"); | |
| } | |
| navigator.mozGetUserMedia(params, function(s) { | |
| output.src = s; | |
| output.play(); | |
| }, function(e) { | |
| alert("Error! " + e); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment