Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

testing sounds

  • Loading branch information...
commit 7e9b3163a2c8c11a9de9a8bf586013101f6a6d60 1 parent 94dd15d
@BlackScorp authored
Showing with 24 additions and 23 deletions.
  1. +14 −16 assets/js/audio.js
  2. +3 −2 assets/js/levels.js
  3. +7 −5 assets/js/loader.js
View
30 assets/js/audio.js
@@ -2,7 +2,7 @@ Crafty.extend({
audio:{
sounds:{},
type: {
- 'mp3': 'audio/mpeg;',
+ 'mp3': 'audio/mpeg',
'ogg': 'audio/ogg; codecs="vorbis"',
'wav': 'audio/wav; codecs="1"',
'mp4': 'audio/mp4; codecs="mp4a.40.2"'
@@ -13,33 +13,32 @@ Crafty.extend({
'wav': 'audio/wav',
'mp4': 'audio/mp4'
},
-
+ volume:1, //Global Volume
add:function(id,url){
- if (!Crafty.support.audio) return this;
- var audio,source,ext,url,canplay;
+ if (!Crafty.support.audio) return;
+
+ var audio,source,ext,path,canplay;
if(arguments.length === 1 && typeof id === "object"){
for(var i in id){
audio = new Audio("");
audio.id = i;
+ //old attribute
audio.autobuffer = true;
audio.preload = "auto";
- audio.volume = 1;
-
+ audio.volume = Crafty.audio.volume;
for(var src in id[i]){
- url = id[i][src];
- ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase();
+ path = id[i][src];
+ ext = path.substr(path.lastIndexOf('.') + 1).toLowerCase();
canplay = audio.canPlayType(this.type[ext]);
- if(canplay !== "" && canplay !== "no"){
+ if(canplay !== "" && canplay !== "no" ){
source = document.createElement('source');
- source.src = url;
+ source.src = path;
source.type=this.srcType[ext];
-
audio.appendChild(source);
- if (!Crafty.assets[url]) Crafty.assets[url] = audio;
-
-
+ if (!Crafty.assets[path]) Crafty.assets[path] = audio;
}
+
}
this.sounds[i] = {
obj:audio,
@@ -61,10 +60,9 @@ Crafty.extend({
var s = this.sounds[id];
- s.obj.volume = 1 || volume;
+ s.obj.volume = Crafty.audio.volume || volume;
if(s.obj.currentTime) s.obj.currentTime = 0;
- // s.obj.mozCurrentSampleOffset = -10;
s.obj.play();
s.played ++;
View
5 assets/js/levels.js
@@ -8,7 +8,7 @@ Crafty.scene("Loading",function(){
toLoad.push(i);
}
-
+
//Setup background image
Crafty.background("url("+game_path+"assets/img/loading.jpg) black");
@@ -53,7 +53,8 @@ Crafty.scene("Loading",function(){
function(e) {
//uh oh, error loading
- console.log("Error on loading: "+e.obj.src);
+ console.log("Error on loading: ");
+ console.log(e.obj);
}
);
View
12 assets/js/loader.js
@@ -58,15 +58,16 @@ Crafty.extend({
event = '';
ext = current.substr(current.lastIndexOf('.') + 1).toLowerCase();
if(this.assets[current]){
- obj = this.assets[current];
+ obj = this.assets[current];
+
}else{
obj =null;
}
if (Crafty.support.audio && (ext === "mp3" || ext === "wav" || ext === "ogg" || ext === "mp4")) {
- event = 'loadedmetadata';
- //Chrome has problems with mp3
+ event = 'oncanplaythrough';
+ //Chrome has problems with mp3 canplaystate is maybe
if (navigator.userAgent.indexOf('Chrome') != -1 && ext === "mp3") j++;
} else if (ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "png") {
event = 'load';
@@ -92,6 +93,7 @@ Crafty.extend({
};
//Error function
function err(){
+
if (onerror)
onerror({
loaded: j,
@@ -103,7 +105,7 @@ Crafty.extend({
j++;
if(j === total && oncomplete) oncomplete();
};
-
+
if (obj.attachEvent) { //IE
obj.attachEvent('on' + event, pro);
@@ -112,7 +114,7 @@ Crafty.extend({
obj.addEventListener(event, pro, false);
obj.addEventListener('error', err, false);
}
-
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.