- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / examples / api / audio / example.js
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Called by the common.js module.
6 function attachListeners() {
7   document.getElementById('playButton').addEventListener('click', playSound);
8   document.getElementById('stopButton').addEventListener('click', stopSound);
9   document.getElementById('frequencyField').addEventListener('change',
10       changeFrequency);
11 }
12
13 // Called by the common.js module.
14 function moduleDidLoad() {
15   // The module is not hidden by default so we can easily see if the plugin
16   // failed to load.
17   common.hideModule();
18 }
19
20 function getFrequencyElement() {
21   return document.getElementById('frequencyField');
22 }
23
24 function playSound() {
25   common.naclModule.postMessage('setFrequency:' + getFrequencyElement().value);
26   common.naclModule.postMessage('playSound');
27 }
28
29 function stopSound() {
30   common.naclModule.postMessage('stopSound');
31 }
32
33 function changeFrequency() {
34   common.naclModule.postMessage('setFrequency:' + getFrequencyElement().value);
35 }
36
37 // Called by the common.js module.
38 function handleMessage(e) {
39   getFrequencyElement().value = message_event.data;
40 }