AMERICA...FUCK YEA

This commit is contained in:
Egor 2015-10-02 09:34:37 -07:00
parent 1eacf06bb4
commit 4077c8f3f8
2 changed files with 41 additions and 23 deletions

View file

@ -243,9 +243,7 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
{audio: true}, {audio: true},
(stream) => { (stream) => {
this.changePlayerControl('usingMic', value); this.changePlayerControl('usingMic', value);
var audio = new Audio(), dancer = this.get('dancer'); var dancer = this.get('dancer');
audio.src = window.URL.createObjectURL(stream);
if(dancer.audio) { if(dancer.audio) {
dancer.pause(); dancer.pause();
@ -257,9 +255,8 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
playing: true playing: true
}); });
dancer.load(audio); dancer.load(stream, true);
dancer.setVolume(0); dancer.setVolume(0);
dancer.play();
}, },
function(err) { function(err) {
console.log('Error during navigator.getUserMedia: ' + err.name + ', ' + err.message + ', ' + err.constraintName); console.log('Error during navigator.getUserMedia: ' + err.name + ', ' + err.message + ', ' + err.constraintName);
@ -413,8 +410,23 @@ export default Em.Component.extend(musicControlMixin, visualizerMixin, {
kick.on(); kick.on();
dancer.bind('loaded', function(){ dancer.bind('loaded', () => {
self.set('timeTotal', Math.round(dancer.audio.duration)); if(!this.get('usingMic')){
this.set('timeTotal', Math.round(dancer.audio.duration));
}
});
dancer.bind('update', function(){
var waveform = this.getWaveform(), spectrum = this.getSpectrum(), sumS = 0, sumW = 0;
for (let i = 0, l = spectrum.length; i < l && i < 512; i++ ) {
sumS += spectrum[i];
}
for (let i = 0, l = waveform.length; i < l && i < 512; i++ ) {
sumW += waveform[i];
}
console.log('sumW: ' + sumW + ', sumS: ' + sumS)
}); });
this.setProperties({ this.setProperties({

38
vendor/dancer.js vendored
View file

@ -18,9 +18,7 @@
Dancer.prototype = { Dancer.prototype = {
load : function ( source ) { load : function ( source, useMic ) {
var path;
// Loading an Audio element // Loading an Audio element
if ( source instanceof HTMLElement ) { if ( source instanceof HTMLElement ) {
this.source = source; this.source = source;
@ -29,17 +27,20 @@
} }
// Loading an object with src, [codecs] // Loading an object with src, [codecs]
} else if(source instanceof EventTarget){
this.source = source;
} else { } else {
this.source = window.Audio ? new Audio() : {}; this.source = window.Audio ? new Audio() : {};
this.source.src = Dancer._makeSupportedPath( source.src, source.codecs ); this.source.src = Dancer._makeSupportedPath( source.src, source.codecs );
} }
this.audio = this.audioAdapter.load( this.source ); this.useMic = useMic === true;
this.audio = this.audioAdapter.load(this.source, this.useMic);
return this; return this;
}, },
/* Controls */ /* Controls */
play : function () { play : function () {
this.audioAdapter.play(); this.audioAdapter.play();
return this; return this;
@ -57,7 +58,6 @@
/* Actions */ /* Actions */
createKick : function ( options ) { createKick : function ( options ) {
return new Dancer.Kick( this, options ); return new Dancer.Kick( this, options );
}, },
@ -380,9 +380,10 @@
adapter.prototype = { adapter.prototype = {
load : function ( _source ) { load : function (_source, useMic) {
var _this = this; var _this = this;
this.audio = _source; this.audio = _source;
this.useMic = useMic;
this.isLoaded = false; this.isLoaded = false;
this.progress = 0; this.progress = 0;
@ -450,7 +451,7 @@
}, },
update : function ( e ) { update : function ( e ) {
if ( !this.isPlaying || !this.isLoaded ) return; if ((!this.isPlaying || !this.isLoaded) && this.useMic !== true ) return;
var var
buffers = [], buffers = [],
@ -476,17 +477,22 @@
}; };
function connectContext () { function connectContext () {
try{ try {
this.source = this.context.createMediaElementSource( this.audio ); if(this.useMic){
} catch(err){ this.source = this.context.createMediaStreamSource(this.audio);
} else {
this.source = this.context.createMediaElementSource(this.audio);
}
} catch (err) {
console.log('Dancer: '+ err);
return; return;
} }
this.source.connect( this.proc ); this.source.connect(this.proc);
this.source.connect( this.gain ); this.source.connect(this.gain);
//this.source.connect( this.filter ); //this.source.connect( this.filter );
this.gain.connect( this.context.destination ); this.gain.connect(this.context.destination);
this.proc.connect( this.context.destination ); this.proc.connect(this.context.destination);
//this.filter.connect( this.context.destination ); //this.filter.connect( this.context.destination );
this.isLoaded = true; this.isLoaded = true;
@ -527,7 +533,7 @@
}, false); }, false);
this.audio.addEventListener( 'progress', function ( e ) { this.audio.addEventListener( 'progress', function ( e ) {
if ( e.currentTarget.duration ) { if ( e.currentTarget.duration && e.currentTarget.duration !== Infinity) {
_this.progress = e.currentTarget.seekable.end( 0 ) / e.currentTarget.duration; _this.progress = e.currentTarget.seekable.end( 0 ) / e.currentTarget.duration;
} }
}, false); }, false);