-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.gamequery.soundwrapper.html5-0.4.0.js
51 lines (44 loc) · 1.74 KB
/
jquery.gamequery.soundwrapper.html5-0.4.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* gameQuery rev. $Revision$
*
* Copyright (c) 2008 Selim Arsever (gamequery.onaluf.org)
* licensed under the MIT (MIT-LICENSE.txt)
*/
// this allow to used the convenient $ notation in a plugins
(function($) {
// Here is a bogus soundWrapper written as an example
$.gameQuery = $.extend($.gameQuery, {
SoundWrapper: function(url, loop) {
this.audio = new Audio();
// start loading the sound. Should turn this.ready to true once done.
this.load = function(){
this.audio.src = url;
this.audio.loop = loop;
this.audio.load();
};
// plays the sound if this.ready == true
this.play = function(){
this.audio.play();
};
// pauses the sound if it is playing
this.pause = function(){
this.audio.pause();
};
// stops the sound if it is playing, rewind (even if paused)
this.stop = function(){
this.audio.pause();
this.audio.currentTime = this.audio.startTime;
};
// mutes the sound without stoping it
this.muted = function(mute){
this.audio.muted = true;
}
// returns true if the sound is ready to be played
this.ready = function(){
return this.audio.readyState == this.audio.HAVE_ENOUGH_DATA;
};
// add the sound to the manager
$.gameQuery.resourceManager.addSound(this);
return true;
}});
})(jQuery);