2 * Copyright (c) 2012, Intel Corporation.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 function GameSound(id, src, preload, loop) {
11 var audioElement = document.createElement('audio');
12 audioElement.setAttribute("id", id);
13 audioElement.setAttribute("src", src);
14 audioElement.setAttribute("preload", preload);
16 audioElement.setAttribute("loop", "loop");
17 document.body.appendChild(audioElement);
21 this.soundobj = document.getElementById(id);
24 this.loop = (loop == undefined)?false:loop;
25 this.focus = function focus() {
29 if(me.enable&&me.loop)
33 this.blur = function blur() {
37 if(me.enable&&me.loop)
41 window.addEventListener('focus', me.focus, false);
42 window.addEventListener('blur', me.blur, false);
44 this.play = function play() {
49 this.pause = function pause() {
51 this.soundobj.pause();