forked from onaluf/gameQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.gamequery.soundwrapper.jPlayer.js
executable file
·75 lines (65 loc) · 2.33 KB
/
jquery.gamequery.soundwrapper.jPlayer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* gameQuery rev. $Revision$
*
* Copyright (c) 2008 Selim Arsever (gamequery.onaluf.org)
* licensed under the MIT (MIT-LICENSE.txt)
*/
/**
* To use this wrapper you will need:
* 1) Include SoundManager2.js before this script
* 2) Give SoundManager2 the position of the swf ie. : soundManager.url = './path/to/swf'
* 3) Optionally deactivate the debug mode from SoundManager2
*/
// this allows use of the convenient $ notation in a plugin
(function($) {
soundManager.url = './'
// Here is a bogus soundWrapper written as an example
$.extend($.gameQuery, {
SoundWrapper: function(url, loop) {
// start loading the sound. Should turn this.ready to true once done.
this.load = function(){
this.sound = soundManager.createSound({
id: this.id,
url: url,
autoplay: false,
autoLoad: true
});
};
// plays the sound if this.ready == true
this.play = function(){
if(loop){
this.sound.play({
onfinish: function() {
this.play();
}
});
} else {
this.sound.play();
}
};
// pauses the sound if it is playing
this.pause = function(){
this.sound.pause();
};
// stops the sound if it is playing, rewind (even if paused)
this.stop = function(){
this.sound.stop();
};
// mutes the sound without stopping it
this.muted = function(mute){
if(mute){
this.sound.mute()
} else {
this.sound.unmute();
}
}
// returns true if the sound is ready to be played
this.ready = function(){
return this.sound.readyState==3
};
// add the sound to the manager
this.id = 'sound_'+$.gameQuery.resourceManager.sounds.length;
$.gameQuery.resourceManager.addSound(this);
return true;
}});
})(jQuery);