Skip to content

Commit

Permalink
Add new load method to accept a config object or audio element
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Aug 9, 2012
1 parent 8a00f75 commit e173c0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/dancer.js
Expand Up @@ -19,10 +19,22 @@

Dancer.prototype = {

load : function ( source, codecs ) {
this.source = source instanceof HTMLElement ?
source :
Dancer._makeSupportedPath( source, codecs );
load : function ( source ) {
var path;

// Loading an Audio element
if ( source instanceof HTMLElement ) {
this.source = source;
if ( Dancer.isSupported() === 'flash' ) {
this.source = { src: Dancer._getMP3SrcFromAudio( source ) };
}

// Loading an object with src, [codecs]
} else {
this.source = window.Audio ? new Audio() : {};
this.source.src = Dancer._makeSupportedPath( source.src, source.codecs );
}

this.audio = this.audioAdapter.load( this.source );
return this;
},
Expand Down Expand Up @@ -102,7 +114,7 @@
isLoaded : function () {
return this.audioAdapter.isLoaded;
},

isPlaying : function () {
return this.audioAdapter.isPlaying;
},
Expand Down
9 changes: 9 additions & 0 deletions src/support.js
Expand Up @@ -71,6 +71,15 @@
}
};

Dancer._getMP3SrcFromAudio = function ( audioEl ) {
var sources = audioEl.children;
if ( audioEl.src ) { return audioEl.src; }
for ( var i = sources.length; i--; ) {
if (( sources[ i ].type || '' ).match( /audio\/mpeg/ )) return sources[ i ].src;
}
return null;
};

// Browser detection is lame, but Safari 6 has Web Audio API,
// but does not support processing audio from a Media Element Source
// https://gist.github.com/3265344
Expand Down

0 comments on commit e173c0e

Please sign in to comment.