[email protected] 8 years ago
parent
commit
da6fd89b43

File diff suppressed because it is too large
+ 0 - 0
examples/SoundDemo/proj.emscripten/SoundDemo.js


+ 25 - 27
examples/SoundDemo/proj.emscripten/js2cpp.js

@@ -1,31 +1,29 @@
 
 
-var js2cppX = {
-	alloc:function(){
-		var context = {
-			_items:{},
-			_id:0,
-			create:function (data, id) {
-				if (typeof(id) === "undefined")
-				{
-					this._id += 1;
-					id = this._id;
+var js2cppX = function(){
+	return {
+				_items:{},
+				_id:0,
+				create:function (data, id) {
+					if (typeof(id) === "undefined")
+					{
+						this._id += 1;
+						id = this._id;
+					}
+
+					this._items[id] = data;
+					return id;
+				},
+				get:function(id){
+					return this._items[id];
+				},
+				free:function(id){
+					delete this._items[id];
+				},
+				get_size:function(){
+					return Object.keys(this._items).length;
 				}
 				}
+			};
+	};
 
 
-				this._items[id] = data;
-				return id;
-			},
-			get:function(id){
-				return this._items[id];
-			},
-			free:function(id){
-				delete this._items[id];
-			},
-			get_size:function(){
-				return Object.keys(this._items).length;
-			}
-		}
-		return context;
-	}
-};
 
 
-var js2cpp = js2cppX.alloc();
+var js2cpp = js2cppX();

+ 1 - 1
examples/SoundDemo/proj.emscripten/preloading.js

@@ -50,7 +50,7 @@ function Preloading(id){
 
 
             
             
             //t += "/";
             //t += "/";
-    		preloadFile("data/" + path, function(e){
+    		preloadFile(path, function(e){
                 var result = new Uint8Array(e.currentTarget.response);
                 var result = new Uint8Array(e.currentTarget.response);
 
 
                 createFolder(path);
                 createFolder(path);

+ 21 - 10
examples/SoundDemo/proj.emscripten/sound.js

@@ -11,20 +11,24 @@ function myb64(bytes)
 
 
 function loopEnded()
 function loopEnded()
 {
 {
-	this.currentTime = 0;
-	this.play();
+	var buffer = .4;
+	if(this.currentTime > this.duration - buffer)
+	{
+        this.currentTime = 0;
+        this.play()
+	};
 }
 }
 
 
 var sound = {
 var sound = {
 	j2c: null,
 	j2c: null,
 	init: function() {
 	init: function() {
-		this.j2c = js2cppX.alloc();
+		this.j2c = js2cppX();
 	},
 	},
 	create: function(){
 	create: function(){
 
 
 	},
 	},
 	play: function(path, volume, loop){
 	play: function(path, volume, loop){
-		try{
+		try {
 			var data = FS.readFile(path, {encoding:'binary'});	
 			var data = FS.readFile(path, {encoding:'binary'});	
 		}
 		}
 		catch(er)
 		catch(er)
@@ -39,13 +43,15 @@ var sound = {
 		a.src = src;
 		a.src = src;
 		a.play();
 		a.play();
 		a.volume = volume;
 		a.volume = volume;
+		//a.loop = true;
+
 
 
 		if (loop)
 		if (loop)
 		{
 		{
-			a.addEventListener('ended', loopEnded, false);
+			a.addEventListener('timeupdate', loopEnded, false);
 		}
 		}
 
 
-		var obj = {instance:a, looped:loop};
+		var obj = {instance:a, looped:loop, path:path};
 
 
 		return this.j2c.create(obj);
 		return this.j2c.create(obj);
 	},
 	},
@@ -60,9 +66,9 @@ var sound = {
 			return;
 			return;
 		s.looped = loop;
 		s.looped = loop;
 		if (loop)
 		if (loop)
-			s.instance.addEventListener('ended', loopEnded, false);
+			s.instance.addEventListener('timeupdate', loopEnded, false);
 		else
 		else
-			s.instance.removeEventListener('ended', loopEnded);
+			s.instance.removeEventListener('timeupdate', loopEnded);
 
 
 	},
 	},
 	setVolume: function(id, volume){
 	setVolume: function(id, volume){
@@ -75,7 +81,9 @@ var sound = {
 		var s = sound.get(id);
 		var s = sound.get(id);
 		if (!s)
 		if (!s)
 			return;
 			return;
+		console.log("pause " + s.path + " " + s.instance.readyState);
 		s.instance.pause();
 		s.instance.pause();
+		console.log("pause end" + s.path + " " + s.instance.readyState);
 	},
 	},
 	resume: function(id){
 	resume: function(id){
 		var s = sound.get(id);
 		var s = sound.get(id);
@@ -88,8 +96,11 @@ var sound = {
 		if (!s)
 		if (!s)
 			return;
 			return;
 		if (s.looped)
 		if (s.looped)
-			s.instance.removeEventListener('ended', loopEnded);
-		s.instance.pause(); 
+			s.instance.removeEventListener('timeupdate', loopEnded);
+		console.log("stop " + s.path + " " + s.instance.readyState);
+		if (s.instance.readyState == 4)
+				s.instance.pause(); 
+		console.log("stop end" + s.path + " " + s.instance.readyState);
 	},
 	},
 	update: function(id){
 	update: function(id){
 		var s = sound.get(id);
 		var s = sound.get(id);

+ 1 - 1
src/sound/ResSound.cpp

@@ -141,7 +141,7 @@ namespace oxygine
 
 
             EM_ASM_ARGS(
             EM_ASM_ARGS(
             {
             {
-                assetsPreloader.add(Pointer_stringify($0));
+                preload_file(Pointer_stringify($0));
             }, rs->getPath().c_str());
             }, rs->getPath().c_str());
         }
         }
 #endif
 #endif

Some files were not shown because too many files changed in this diff