2
* Copyright (c) 2013, 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
9
var Sound = function (config) {
10
config = config || {};
11
config.url = config.url || '';
12
config.loop = (config.loop === true ? true : false);
15
smokesignals.convert(this);
18
this.isPlaying = false;
20
this.audio = new Audio();
22
this.audio.addEventListener('canplaythrough', function () {
23
var firstTime = !self.ready;
32
this.audio.addEventListener('pause', function () {
33
self.isPlaying = false;
36
this.audio.addEventListener('play', function () {
37
self.isPlaying = true;
40
// this is to work around Android xwalk not looping audio
41
// when the loop attribute is set:
42
// https://github.com/crosswalk-project/crosswalk/issues/659
43
this.audio.addEventListener('ended', function () {
44
self.isPlaying = false;
50
this.audio.autoplay = false;
51
this.audio.preload = 'auto';
52
this.audio.src = config.url;
55
Sound.prototype.play = function () {
60
if (!this.isPlaying) {
65
Sound.prototype.pause = function () {