Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: ppapi/examples/audio_input/audio_input.html

Issue 11411047: Introduce PPB_AudioInput_Dev v0.3 and refactor the device enumeration code: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <!-- 3 <!--
4 Copyright (c) 2012 The Chromium Authors. All rights reserved. 4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be 5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file. 6 found in the LICENSE file.
7 --> 7 -->
8 <head> 8 <head>
9 <title>Audio Input Example</title> 9 <title>Audio Input Example</title>
10 <script type="text/javascript"> 10 <script type="text/javascript">
11 var device_array = []; 11 var monitor_device_array = [];
12 var enumerate_device_array = [];
13 var monitor_notification_count = 0;
12 14
13 function HandleMessage(message_event) { 15 function HandleMessage(message_event) {
14 if (message_event.data) { 16 if (message_event.data) {
15 var status = document.getElementById('status'); 17 var status = document.getElementById('status');
16 if (message_event.data == 'EnumerationFailed') { 18 if (message_event.data == 'EnumerationFailed') {
17 status.innerText = 'Device enumeration failed!'; 19 status.innerText = 'Device enumeration failed!';
20 } else if (message_event.data == 'MonitorDeviceChangeFailed') {
21 status.innerText = 'Monitor device change failed!';
18 } else if (message_event.data == 'OpenFailed') { 22 } else if (message_event.data == 'OpenFailed') {
19 status.innerText = 'Open device failed!'; 23 status.innerText = 'Open device failed!';
20 } else if (message_event.data == 'StartFailed') { 24 } else if (message_event.data == 'StartFailed') {
21 status.innerText = 'Start capturing failed!'; 25 status.innerText = 'Start capturing failed!';
22 } else if (message_event.data == 'StopFailed') { 26 } else if (message_event.data == 'StopFailed') {
23 status.innerText = 'Stop capturing failed!'; 27 status.innerText = 'Stop capturing failed!';
24 } else { 28 } else {
25 device_array = message_event.data.split('#__#'); 29 AddDevices(message_event.data);
26
27 var list = document.getElementById('device_list');
28 for (var i = 0; i < device_array.length; ++i) {
29 var list_item = document.createElement('li');
30 var link = document.createElement('a');
31 link.href = 'javascript:UseDesignatedDevice(' + i + ');';
32 link.innerText = device_array[i];
33 list_item.appendChild(link);
34 list.appendChild(list_item);
35 }
36 } 30 }
37 } 31 }
38 } 32 }
39 33
40 function UseDesignatedDevice(index) { 34 function AddDevices(command) {
41 UseDevice(device_array[index], index); 35 var serialized_names = '';
36 var is_monitor = false;
37 if (command.search('Monitor:') == 0) {
38 serialized_names = command.substr(8);
39 is_monitor = true;
40 monitor_notification_count++;
41 var counter = document.getElementById('notification_counter');
42 counter.innerText = monitor_notification_count;
43 } else if (command.search('Enumerate:') == 0) {
44 serialized_names = command.substr(10);
45 } else {
46 status.innerText = 'Unrecognized command!';
47 return;
48 }
49
50 var storage = serialized_names.length != 0 ?
51 serialized_names.split('#__#') : [];
52 if (is_monitor)
53 monitor_device_array = storage;
54 else
55 enumerate_device_array = storage;
56
57 var list = document.getElementById(
58 is_monitor ? 'monitor_list' : 'enumerate_list');
59 while (list.firstChild)
60 list.removeChild(list.firstChild);
61
62 for (var i = 0; i < storage.length; ++i) {
63 AppendDevice(
64 list, storage[i],
65 'javascript:UseDesignatedDevice(' + is_monitor + ',' + i + ');');
66 }
67 }
68
69 function AppendDevice(list, text, href) {
70 var list_item = document.createElement('li');
71 var link = document.createElement('a');
72 link.href = href;
73 link.innerText = text;
74 list_item.appendChild(link);
75 list.appendChild(list_item);
76 }
77
78 function UseDesignatedDevice(is_monitor, index) {
79 if (is_monitor)
80 UseDevice(monitor_device_array[index], 'Monitor:' + index);
81 else
82 UseDevice(enumerate_device_array[index], 'Enumerate:' + index);
42 } 83 }
43 84
44 function UseDefaultDevice() { 85 function UseDefaultDevice() {
45 UseDevice('Default', 'UseDefault'); 86 UseDevice('Default', 'UseDefault');
46 } 87 }
47 88
48 function UseDevice(display_text, command) { 89 function UseDevice(display_text, command) {
49 var in_use_device = document.getElementById('in_use_device'); 90 var in_use_device = document.getElementById('in_use_device');
50 in_use_device.innerText = display_text; 91 in_use_device.innerText = display_text;
51 var plugin = document.getElementById('plugin'); 92 var plugin = document.getElementById('plugin');
52 plugin.postMessage(command); 93 plugin.postMessage(command);
53
54 var available_devices = document.getElementById('available_devices');
55 available_devices.parentNode.removeChild(available_devices);
56
57 var control_panel = document.getElementById('control_panel');
58 control_panel.style.display = 'block';
59 } 94 }
60 95
61 function Stop() { 96 function Stop() {
62 var plugin = document.getElementById('plugin'); 97 var plugin = document.getElementById('plugin');
63 plugin.postMessage('Stop'); 98 plugin.postMessage('Stop');
64 } 99 }
65 100
66 function Start() { 101 function Start() {
67 var plugin = document.getElementById('plugin'); 102 var plugin = document.getElementById('plugin');
68 plugin.postMessage('Start'); 103 plugin.postMessage('Start');
69 } 104 }
70 105
71 function Initialize() { 106 function Initialize() {
72 var plugin = document.getElementById('plugin'); 107 var plugin = document.getElementById('plugin');
73 plugin.addEventListener('message', HandleMessage, false); 108 plugin.addEventListener('message', HandleMessage, false)
74 plugin.postMessage('PageInitialized'); 109 plugin.postMessage('PageInitialized');
75 } 110 }
76 111
77 document.addEventListener('DOMContentLoaded', Initialize, false); 112 document.addEventListener('DOMContentLoaded', Initialize, false);
78 </script> 113 </script>
79 </head> 114 </head>
80 115
81 <body> 116 <body>
82 <embed id="plugin" type="application/x-ppapi-example-audio-input" 117 <embed id="plugin" type="application/x-ppapi-example-audio-input"
83 width="800" height="400"/> 118 width="800" height="400"/>
84 <div style="margin-bottom:10px">In-use device: 119 <div style="margin-bottom:10px">In-use device:
85 <span id="in_use_device" style="font-weight:bold">None</span> 120 <span id="in_use_device" style="font-weight:bold">None</span>
86 </div> 121 </div>
87 <div id="available_devices"> 122 <div id="available_devices">
88 Available device(s), choose one to open: 123 Available device(s), choose one to open:
89 <ul id="device_list"> 124 <ul>
90 <li><a href="javascript:UseDefaultDevice();"> 125 <li><a href="javascript:UseDefaultDevice();">
91 Default - use interface version 0.2 and NULL device ref</a></li> 126 Default - use NULL device ref</a></li>
92 </ul> 127 </ul>
128 <div>
129 <ul>List retrieved by MonitorDeviceChange(), will change when
130 pluging/unpluging devices: (Notifications received:
131 <span style="font-weight:bold" id="notification_counter">0</span>
132 )</ul>
133 <ul id="monitor_list"/>
134 </div>
135 <div>
136 <ul>List retrieved by EnumerateDevices(), never updated after the page is
137 initialized:</ul>
138 <ul id="enumerate_list"/>
139 </div>
93 </div> 140 </div>
94 <div id="control_panel" style="display:none"> 141 <div id="control_panel">
95 <a href="javascript:Stop();">Stop</a> 142 <a href="javascript:Stop();">Stop</a>
96 <a href="javascript:Start();">Start</a> 143 <a href="javascript:Start();">Start</a> (known issue: crbug.com/161058)
97 </div> 144 </div>
98 <div id="status"></div> 145 <div id="status"></div>
99 </body> 146 </body>
100 </html> 147 </html>
OLDNEW
« no previous file with comments | « ppapi/examples/audio_input/audio_input.cc ('k') | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698