浏览代码

added stopAll()

ncannasse 10 年之前
父节点
当前提交
faf40ade08
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      hxd/snd/Worker.hx

+ 16 - 0
hxd/snd/Worker.hx

@@ -12,6 +12,7 @@ private enum Message {
 	SetTime( id : Int, t : Float );
 	FadeEnd( id : Int, uid : Int );
 	Active( b : Bool );
+	StopAll;
 }
 
 private class WorkerChannel extends NativeChannel {
@@ -71,6 +72,19 @@ class Worker extends hxd.Worker<Message> {
 		return c;
 	}
 
+	public function stopAll() {
+		if( !isWorker ) {
+			send(StopAll);
+			return;
+		}
+		for( c in channels ) {
+			if( c.channel == null ) continue;
+			c.channel.stop();
+			c.channel = null;
+			c.channels = [];
+		}
+	}
+
 	function cleanChannels() {
 		for( c in channels )
 			if( c.channels.length == 0 && c.channel != null && c.busy <= -2 ) {
@@ -166,6 +180,8 @@ class Worker extends hxd.Worker<Message> {
 			}
 		case SetGlobalVolume(v):
 			volume = v;
+		case StopAll:
+			stopAll();
 		}
 	}