/
jquery.sound.js
49 lines (44 loc) · 1.21 KB
/
jquery.sound.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
/*
*
* jquery.sound.js
* (c) Vipin Kumar Rajput
*
*/
(function($) {
//
// plugin definition
//
$.fn.soundPlay = function(options) {
// build main options before element iteration
var opts = $.extend({}, $.fn.soundPlay.defaults, options);
// iterate and reformat each matched element
if(opts.command == "play") {
$.fn.soundPlay.play(opts);
} else if(opts.command == "stop") {
$.fn.soundPlay.stop(opts);
} else {
}
};
function debug($obj) {
if (window.console && window.console.log)
window.console.log('soundPlay: ' + $obj.size());
};
$.fn.soundPlay.play = function(opts) {
url = opts.url;
id = opts.playerId;
$("body").append('<embed id="' + id + '" src="'+url+'" autostart="true" hidden="true"></embed>');
return false;
};
$.fn.soundPlay.stop = function(opts) {
$('#'+opts.playerId).remove();
return false;
};
//
// plugin defaults
//
$.fn.soundPlay.defaults = {
url: '',
playerId: 'player',
command: 'play'
};
})(jQuery);