- From: Dominique Hazael-Massieux via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 04 Aug 2010 13:37:01 +0000
- To: public-dap-commits@w3.org
Update of /sources/public/2009/dap/camera In directory hutz:/tmp/cvs-serv10111 Modified Files: Overview.html Log Message: added example of JavaScript usage; fixed mediafiledataerror interface Index: Overview.html =================================================================== RCS file: /sources/public/2009/dap/camera/Overview.html,v retrieving revision 1.104 retrieving revision 1.105 diff -u -d -r1.104 -r1.105 --- Overview.html 4 Aug 2010 13:14:37 -0000 1.104 +++ Overview.html 4 Aug 2010 13:36:59 -0000 1.105 @@ -101,7 +101,7 @@ <p>If the user selects files of whose MIME types match <code>image/*</code>, <code>sound/*</code>, or <code>video/*</code> (on the filesystem or via a successful media capture), the relevant files in the <code>files</code> attribute [[HTML5]] MUST implement the <code>MediaFile</code> interface.</p> - <pre class="example sh_javascript_dom"><input type="file" accept="image/*"> </pre> + <pre class="example sh_javascript_dom"><input type="file" accept="image/*" id="capture"> </pre> </section> <section id="captureparam"> @@ -119,13 +119,39 @@ <p class="note">The values and their exact meaning are still very much in flux.</p> <p>For example, the following code indicates that the user is expected to upload an image from the device camera:</p> - <pre class="example sh_javascript_dom"><input type="file" accept="image/*;capture=camera"> </pre> + <pre class="example sh_javascript_dom"><input type="file" accept="image/*;capture=camera" id="capture"> </pre> <p>A possible rendering of a file picker taking this parameter into account is offered in the <a href="#uiexamples">User Interface Examples appendix</a>.</p> </section> <section id="api"> <h2>WebIDL interfaces</h2> + <section id="jsexample"><h3>Example</h3> + <p>After the user successfully captured or selected an existing media file, the format properties of the file can be retrieved as follow:</p> + <pre class="example sh_javascript_dom"><code>var captureInput = document.getElementById('capture'); +var file = captureInput.files[0]; +if (file) { + file.<strong>getFormatData(displayFormatData, errorHandler)</strong>; +} + +function displayFormatData(formatData) { + var mainType = file.type.split("/")[0]; // "image", "video" or "audio" + var mediaDescriptionNode = document.createElement("p"); + if (mainType === "image") { + mediaDescriptionNode.appendChild(document.createNode("This is an image of dimensions " + <strong>formatData.width</strong> + "x" + <strong>formatData.height</strong>); + } else { + mediaDescriptionNode.appendChild(document.createNode("Duration: " + (<strong>formatData.duration</strong> / 1000) + "s"); + } + captureInput.parentNode.insertBefore(mediaDescriptionNode, captureInput); +} + +function errorHandler(error) { + alert("Couldn’t retrieve format properties for the selected file (error code " + error.code + ")"); +} +</code></pre> +</section> + + <section id="formatdata"><h3><a>MediaFileData</a> interface</h3> <p><code>MediaFileData</code> encapsulates format information of a media @@ -230,6 +256,8 @@ <dd> The requested method timed out before it could be completed. </dd> + <dt>readonly attribute unsigned short code</dt> + <dd>An error code assigned by an implementation when an error has occurred in retrieving format data.</dd> </dl> </section>
Received on Wednesday, 4 August 2010 13:37:02 UTC