website/public/js/modules/music-player.js

53 lines
886 B
JavaScript
Raw Permalink Normal View History

2015-10-06 12:36:47 -04:00
(function($){
$.fn.musicPlayer = function(opt) {
var settings, player, getVolume, setVolume, isPlaying, play, pause, getTime, setTime;
settings = $.extend({
'audio': '#music-player',
'volume': .5,
'startTime': 0
}, opt);
player = $(settings.player);
getVolume = function() {
return player.prop('volume');
}
setVolume = function(volume) {
player.prop('volume', volume);
};
isPlaying = function() {
return !player.prop('paused');
};
play = function() {
if (!isPlaying()) {
player.trigger('play');
}
};
pause = function() {
if (isPlaying()) {
player.trigger('pause');
}
};
getTime = function() {
return player.prop('currentTime');
};
setTime = function(time) {
player.prop('currentTime', time);
};
// Default actions
setVolume(settings.volume);
setTime(setTime.startTime);
};
})(jQuery);