Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volume issues #34

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 87 additions & 45 deletions src/plugins/projekktor.controlbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ jQuery(function ($) {
var isVisible = this.cb.hasClass('active'),
ref = this,
fixed = this.getConfig('fixedVolume'),
toggleMute = (this.controlElements['mute'].hasClass('toggle') || this.controlElements['unmute'].hasClass('toggle') || this.getConfig('toggleMute'));
toggleMute = (this.controlElements['mute'].hasClass('toggle') || this.controlElements['unmute'].hasClass('toggle') || this.getConfig('toggleMute')),
// check if the volume is in the proper range and correct its value if it's not
volume = volume > 1 ? 1 : volume,
volume = volume < 0 ? 0 : volume;

// hide volume mess in case volume is fixed
this._active('mute', !fixed);
Expand All @@ -612,12 +615,25 @@ jQuery(function ($) {

// make controls visible in order to allow dom manipulations
// this.cb.stop(true, true).show();
if (this.controlElements['vslider'].width() > this.controlElements['vslider'].height()) {
this.controlElements['vmarker'].css('width', volume * 100 + "%");
this.controlElements['vknob'].css('left', volume * 100 + "%");
} else {
this.controlElements['vmarker'].css('height', volume * 100 + "%");
this.controlElements['vknob'].css('top', (100 - volume * 100) + "%");
var vslider = this.controlElements['vslider'],
vmarker = this.controlElements['vmarker'],
vknob = this.controlElements['vknob'],
orientation = vslider.width() > vslider.height() ? "horizontal" : "vertical";

switch(orientation){
case "horizontal":

vmarker.css('width', volume * 100 + "%");
vknob.css('left', Math.round((vslider.width() * volume) - (vknob.width() * volume)) + "px" );

break;

case "vertical":

vmarker.css('height', volume * 100 + "%");
vknob.css('bottom', Math.round((vslider.height() * volume) - (vknob.height() * volume)) + "px" );

break;
}

// "li" hack
Expand Down Expand Up @@ -816,12 +832,16 @@ jQuery(function ($) {

volumeHandler: function (value) {
try {
if (value>0)
if (value>0){
this.cookie('muted', false);

if (!this.cookie('muted'))
}

if (!this.cookie('muted')){
this.cookie('volume', value);
}

} catch(e){console.log(e)}

this.displayVolume(this._getVolume());
},

Expand Down Expand Up @@ -1154,53 +1174,75 @@ jQuery(function ($) {
this._vSliderAct = true;

var ref = this,
sliderIdx = (this.pp.getInFullscreen() === true && this.controlElements['vslider'].length > 1) ? 1 : 0,
knob = $(domObj[sliderIdx]),
slider = $(this.controlElements['vslider'][sliderIdx]),
dx = Math.abs(parseFloat(knob.position().left) - event.clientX),
dy = Math.abs(parseFloat(knob.position().top) - event.clientY),

vslider = ref.controlElements['vslider'],
vmarker = ref.controlElements['vmarker'],
vknob = ref.controlElements['vknob'],

orientation = vslider.width() > vslider.height() ? "horizontal" : "vertical",

volume = 0,
mouseUp = function (mouseupevt) {
ref.playerDom.unbind('mouseup', mouseUp);
slider.unbind('mousemove', mouseMove);
slider.unbind('mouseup', mouseUp);
knob.unbind('mousemove', mouseMove);
knob.unbind('mouseup', mouseUp);

mouseUp = function (mouseUpEvent) {
if(window.onmouseup === undefined){ // IE < 9 has no window mouse events support
$(document).unbind('mousemove', mouseMove);
$(document).unbind('mouseup', mouseUp);
$(document).unbind('mouseleave', mouseUp);
}
else {
$(window).unbind('mousemove', mouseMove);
$(window).unbind('mouseup', mouseUp);
}

ref._vSliderAct = false;

return false;
},

mouseMove = function (dragevent) {
mouseMove = function (dragEvent) {
clearTimeout(ref._cTimer);
var newXPos = (dragevent.clientX - dx),
newXPos = (newXPos > slider.width() - knob.width() / 2) ? slider.width() - (knob.width() / 2) : newXPos,

var newXPos = (dragEvent.clientX - vslider.offset().left),
newXPos = (newXPos > vslider.width()) ? vslider.width() : newXPos,
newXPos = (newXPos < 0) ? 0 : newXPos,
newYPos = (dragevent.clientY - dy),
newYPos = (newYPos > slider.height() - knob.height() / 2) ? slider.height() - (knob.height() / 2) : newYPos,

newYPos = (dragEvent.clientY - vslider.offset().top),
newYPos = (newYPos > vslider.height()) ? vslider.height() : newYPos,
newYPos = (newYPos < 0) ? 0 : newYPos;

if (ref.controlElements['vslider'].width() > ref.controlElements['vslider'].height()) {
knob.css('left', newXPos + 'px');
volume = Math.abs(newXPos / (slider.width() - (knob.width() / 2)));
$(ref.controlElements['vmarker'][sliderIdx]).css('width', volume * 100 + "%");
} else {
knob.css('top', newYPos + 'px');
volume = 1 - Math.abs(newYPos / (slider.height() - (knob.height() / 2)));
$(ref.controlElements['vmarker'][sliderIdx]).css('height', volume * 100 + "%");
}
};



switch(orientation){
case "horizontal":
volume = Math.abs(newXPos / vslider.width());

vmarker.css('width', volume * 100 + "%");
vknob.css('left', Math.round((vslider.width() * volume) - (vknob.width() * volume)) + "px" );

// this.playerDom.mousemove(mouseMove);
this.playerDom.mouseup(mouseUp);
break;

slider.mousemove(mouseMove);
slider.mouseup(mouseUp);
case "vertical":
volume = 1 - Math.abs(newYPos / vslider.height());

vmarker.css('height', volume * 100 + "%");
vknob.css('bottom', Math.round((vslider.height() * volume) - (vknob.height()* volume)) + "px" );

knob.mousemove(mouseMove);
knob.mouseup(mouseUp);
break;
}

ref.pp.setVolume(volume);
return false;
};

if(window.onmouseup === undefined){
$(document).mousemove(mouseMove);
$(document).mouseup(mouseUp);
$(document).mouseleave(mouseUp);
}
else {
$(window).mousemove(mouseMove);
$(window).mouseup(mouseUp);
}
},

handleStartDragListener: function (evt, domObj) {
Expand Down Expand Up @@ -1255,7 +1297,7 @@ jQuery(function ($) {
*******************************/
_getVolume: function() {

var volume = parseFloat(this.cookie('volume') || this.getConfig('volume') || 0.5),
var volume = parseFloat(this.cookie('volume') || this.getConfig('volume')),
muted = this.cookie('muted') || false;

if (this.getConfig('fixedVolume') || volume==null)
Expand Down Expand Up @@ -1298,4 +1340,4 @@ jQuery(function ($) {
return result;
}
}
});
});
3 changes: 2 additions & 1 deletion themes/maccaco/projekktor.style.css
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ controlbar plugin
/* volume slider - right */
.ppvslider {
margin: 13px 5px;
padding: 0 1px;
height: 16px;
width: 60px;
background: url("maccaco.png") no-repeat -781px -13px transparent;
Expand All @@ -335,7 +336,7 @@ controlbar plugin
background: url("maccaco.png") no-repeat -699px -5px transparent;
top: -13px;
left:0;
width: 6px;
width: 4px;
height: 20px;
padding: 0;

Expand Down