Browse Source

added stopAll()

ncannasse 10 năm trước cách đây
mục cha
commit
faf40ade08
1 tập tin đã thay đổi với 16 bổ sung0 xóa
  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();
 		}
 	}