Permalink
Browse files

hopefully fixed it now

  • Loading branch information...
2 parents 92e82c3 + a0836b9 commit df0f1d001f70d636f2b42449e29b5290c0268f2a @BlackScorp committed Mar 5, 2012
Showing with 449 additions and 7 deletions.
  1. +87 −0 assets/js/audio.js
  2. +4 −2 assets/js/crafty.js
  3. +306 −0 assets/js/loader.js
  4. +41 −5 assets/js/sounds.js
  5. +6 −0 assets/js/sprites.js
  6. +5 −0 index.html
View
@@ -0,0 +1,87 @@
+Crafty.extend({
+ audio:{
+ sounds:{},
+ type: {
+ 'mp3': 'audio/mpeg;',
+ 'ogg': 'audio/ogg; codecs="vorbis"',
+ 'wav': 'audio/wav; codecs="1"',
+ 'mp4': 'audio/mp4; codecs="mp4a.40.2"'
+ },
+ srcType: {
+ 'mp3': 'audio/mpeg',
+ 'ogg': 'audio/ogg',
+ 'wav': 'audio/wav',
+ 'mp4': 'audio/mp4'
+ },
+
+ add:function(id,url){
+ if (!Crafty.support.audio) return this;
+ var audio,source,ext,url,canplay;
+ if(arguments.length === 1 && typeof id === "object"){
+ for(var i in id){
+ audio = new Audio("");
+ audio.id = i;
+ audio.autobuffer = true;
+ audio.preload = "auto";
+ audio.volume = 1;
+
+
+ for(var src in id[i]){
+ url = id[i][src];
+ ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase();
+ canplay = audio.canPlayType(this.type[ext]);
+ if(canplay !== "" && canplay !== "no"){
+ source = document.createElement('source');
+ source.src = url;
+ source.type=this.srcType[ext];
+
+ audio.appendChild(source);
+ if (!Crafty.assets[url]) Crafty.assets[url] = audio;
+
+
+ }
+ }
+ this.sounds[i] = {
+ obj:audio,
+ played:0
+ }
+ }
+
+
+ }
+ if(typeof id === "string"){
+
+
+ }
+
+
+ },
+ play:function(id,repeat,volume){
+ if(repeat == 0 || !Crafty.support.audio || !this.sounds[id]) return;
+
+ var s = this.sounds[id];
+
+ s.obj.volume = 1 || volume;
+ if(s.obj.currentTime) s.obj.currentTime = 0;
+
+ // s.obj.mozCurrentSampleOffset = -10;
+ s.obj.play();
+ s.played ++;
+
+ function r(){
+ if(s.played < repeat || repeat == -1){
+ if(this.currentTime) this.currentTime = 0;
+ this.play();
+ s.played ++;
+ }
+
+ }
+ if (s.attachEvent) { //IE
+ s.obj.attachEvent('onended', r);
+ } else { //Everyone else
+ s.obj.addEventListener('ended', r, false);
+ }
+ return s;
+ }
+ }
+});
View
@@ -7219,9 +7219,11 @@ Crafty.c("Text", {
if (Crafty.support.audio && (ext === "mp3" || ext === "wav" || ext === "ogg" || ext === "mp4")) {
obj = new Audio(current);
- event = 'loadstart';
+ event = 'canplay';
canplay = obj.canPlayType(Crafty.audio.type[ext]);
+
if(canplay !== "" && canplay !== "no"){
+ obj.load();
this.assets[current] = obj;
}else{
j--;
@@ -8461,4 +8463,4 @@ Crafty.math.Matrix2D = (function () {
return Matrix2D;
})();
- })(Crafty,window,window.document);
+ })(Crafty,window,window.document);
Oops, something went wrong.

0 comments on commit df0f1d0

Please sign in to comment.