|
|
@ -4,27 +4,26 @@ tag.src = 'https://www.youtube.com/iframe_api'; |
|
|
|
let firstScriptTag = document.getElementsByTagName('script')[0]; |
|
|
|
let firstScriptTag = document.getElementsByTagName('script')[0]; |
|
|
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); |
|
|
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//THE DJ CROSSFADER!!!
|
|
|
|
let crossfader = document.querySelector('#crossfader'); |
|
|
|
let crossfader = document.querySelector('#crossfader'); |
|
|
|
|
|
|
|
|
|
|
|
class player { |
|
|
|
class player { |
|
|
|
trackID; |
|
|
|
trackID; |
|
|
|
// volume;
|
|
|
|
|
|
|
|
// id;
|
|
|
|
|
|
|
|
// iframe;
|
|
|
|
|
|
|
|
player; |
|
|
|
player; |
|
|
|
// node;
|
|
|
|
crossfaderCoef; |
|
|
|
|
|
|
|
|
|
|
|
constructor(id) { |
|
|
|
constructor(id) { |
|
|
|
this.id = id; |
|
|
|
this.id = id; |
|
|
|
this.iframe = document.querySelector('#'+this.id); |
|
|
|
this.iframe = document.querySelector('#'+this.id); |
|
|
|
// console.log('#'+this.id);
|
|
|
|
|
|
|
|
// console.log(this.iframe);
|
|
|
|
|
|
|
|
// this.volume = vol;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.node = this.iframe.parentNode; |
|
|
|
this.node = this.iframe.parentNode; |
|
|
|
this.volume = this.node.querySelector('.volume-slider').value; |
|
|
|
this.volume = this.node.querySelector('.volume-slider').value; |
|
|
|
|
|
|
|
this.volSliderVal = this.node.querySelector('.volume-slider-value'); |
|
|
|
|
|
|
|
this.volVal = this.node.querySelector('.volume-value') |
|
|
|
|
|
|
|
this.volSliderVal.innerHTML = this.volume + '%'; |
|
|
|
this.loadButton = this.node.querySelector('.load-button'); |
|
|
|
this.loadButton = this.node.querySelector('.load-button'); |
|
|
|
this.speedSlider = this.node.querySelector('.speed-slider'); |
|
|
|
this.speedSlider = this.node.querySelector('.speed-slider'); |
|
|
|
this.speedSlider.previousElementSibling.innerHTML = 'Speed: ' + this.speedSlider.value; |
|
|
|
this.speedSlider.nextElementSibling.querySelector('.speed-value').innerHTML = this.speedSlider.value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init(trackID) { |
|
|
|
init(trackID) { |
|
|
@ -40,17 +39,12 @@ class player { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
onPlayerReady(e) { |
|
|
|
onPlayerReady(e) { |
|
|
|
// console.log(e.target);
|
|
|
|
|
|
|
|
// this.node.querySelector('.volumeSlider').value = this.player.getVolume();
|
|
|
|
|
|
|
|
// e.target.playVideo();
|
|
|
|
|
|
|
|
// console.log(e.target);
|
|
|
|
|
|
|
|
// e.target.setVolume(this.volume);
|
|
|
|
|
|
|
|
this.player.setVolume(this.volume); |
|
|
|
this.player.setVolume(this.volume); |
|
|
|
|
|
|
|
|
|
|
|
this.node.querySelector('.volume-slider').addEventListener('input', (e) => { |
|
|
|
this.node.querySelector('.volume-slider').addEventListener('input', (e) => { |
|
|
|
let volume = e.target.value; |
|
|
|
this.volume = e.target.value; |
|
|
|
this.volume = volume; |
|
|
|
this.volSliderVal.innerHTML = this.volume + '%'; |
|
|
|
this.player.setVolume(volume); |
|
|
|
this.volumeUpdate(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.loadButton.addEventListener('click', () => { |
|
|
|
this.loadButton.addEventListener('click', () => { |
|
|
@ -72,11 +66,11 @@ class player { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.speedSlider.addEventListener('input', (e) => { |
|
|
|
this.speedSlider.addEventListener('input', (e) => { |
|
|
|
this.speedSlider.previousElementSibling.innerHTML = 'Speed: ' + e.target.value; |
|
|
|
this.speedSlider.nextElementSibling.querySelector('.speed-value').innerHTML = e.target.value; |
|
|
|
this.player.setPlaybackRate(Number(e.target.value)); |
|
|
|
this.player.setPlaybackRate(Number(e.target.value)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// updateCrossfader(crossfader.value); //Throws an error at the beginning because the second player is not ready yet.
|
|
|
|
this.volumeUpdate(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onPlayerStateChange(e) { |
|
|
|
onPlayerStateChange(e) { |
|
|
@ -103,6 +97,12 @@ class player { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
volumeUpdate() { |
|
|
|
|
|
|
|
let outputVolume = Math.round(this.volume * this.crossfaderCoef); |
|
|
|
|
|
|
|
this.player.setVolume(outputVolume); |
|
|
|
|
|
|
|
this.volVal.innerHTML = outputVolume + '%'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -116,38 +116,65 @@ function onYouTubeIframeAPIReady() { |
|
|
|
playerB.init('PhEuAuhH418'); |
|
|
|
playerB.init('PhEuAuhH418'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// while (bothPlayersReady < 2) {
|
|
|
|
calcCrossfaderCoefs(crossfader.value); |
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
crossfader.addEventListener('input', (e) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
crossfader.addEventListener('input', (e) => { |
|
|
|
|
|
|
|
//Makes the slider stick on the middle
|
|
|
|
if (Math.abs(crossfader.value - 500) < 15) { |
|
|
|
if (Math.abs(crossfader.value - 500) < 15) { |
|
|
|
crossfader.value = 500; |
|
|
|
crossfader.value = 500; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateCrossfader(crossfader.value); |
|
|
|
calcCrossfaderCoefs(crossfader.value); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
let boxShadowStyle = '0 0 3em #ddbddd' |
|
|
|
|
|
|
|
playerA.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(playerA.crossfaderCoef*255)); |
|
|
|
|
|
|
|
playerB.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(playerB.crossfaderCoef*255)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerA.volumeUpdate(); |
|
|
|
|
|
|
|
playerB.volumeUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
function updateCrossfader(input) { |
|
|
|
// updateCrossfader(crossfader.value);
|
|
|
|
let normVal = crossfader.value / 1000; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// let coefB = normVal ** 2;
|
|
|
|
function calcCrossfaderCoefs(input) { |
|
|
|
// let coefA = (1 - normVal) ** 2;
|
|
|
|
let normVal = input / 1000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Classic 'transition' curve
|
|
|
|
let coefB = Math.min(normVal*2, 1); |
|
|
|
let coefB = Math.min(normVal*2, 1); |
|
|
|
let coefA = Math.min((1-normVal)*2, 1); |
|
|
|
let coefA = Math.min((1-normVal)*2, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Cheap smooth curve
|
|
|
|
|
|
|
|
// let coefB = normVal ** 2;
|
|
|
|
|
|
|
|
// let coefA = (1 - normVal) ** 2;
|
|
|
|
|
|
|
|
|
|
|
|
// Sets box-shadow transparency depending on crossfader position
|
|
|
|
//Amplitude-preserving curve (but not power)
|
|
|
|
let boxShadowStyle = '0 0 3em #ddbddd' |
|
|
|
// let coefB = (normVal ** 2) * (3 - 2 * normVal);
|
|
|
|
playerA.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(coefA*255)); |
|
|
|
// let coefA = 1 - coefB;
|
|
|
|
playerB.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(coefB*255)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerA.player.setVolume(playerA.volume * coefA); |
|
|
|
// return [coefA, coefB];
|
|
|
|
playerB.player.setVolume(playerB.volume * coefB); |
|
|
|
playerA.crossfaderCoef = coefA; |
|
|
|
|
|
|
|
playerB.crossfaderCoef = coefB; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// function updateCrossfader(input) {
|
|
|
|
|
|
|
|
// let normVal = crossfader.value / 1000;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // let coefB = normVal ** 2;
|
|
|
|
|
|
|
|
// // let coefA = (1 - normVal) ** 2;
|
|
|
|
|
|
|
|
// let coefB = Math.min(normVal*2, 1);
|
|
|
|
|
|
|
|
// let coefA = Math.min((1-normVal)*2, 1);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Sets box-shadow transparency depending on crossfader position
|
|
|
|
|
|
|
|
// let boxShadowStyle = '0 0 3em #ddbddd'
|
|
|
|
|
|
|
|
// playerA.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(coefA*255));
|
|
|
|
|
|
|
|
// playerB.iframe.style.boxShadow = boxShadowStyle + componentToHex(Math.round(coefB*255));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// playerA.player.setVolume(playerA.volume * coefA);
|
|
|
|
|
|
|
|
// playerB.player.setVolume(playerB.volume * coefB);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// From https://thomaspark.co/projects/needledrop/ by Thomas Park
|
|
|
|
// From https://thomaspark.co/projects/needledrop/ by Thomas Park
|
|
|
|
// function getYouTubeID(url){
|
|
|
|
// function getYouTubeID(url){
|
|
|
|