public void setSound(IMySoundBlock speaker, bool value) { speaker.SelectedSound = "Alert 1"; speaker.LoopPeriod = soundLength; if (value) { if (alarmStarted == null) { ITerminalAction action; action = speaker.GetActionWithName("OnOff_On"); action.Apply(speaker); alarmStarted = DateTime.Now; speaker.Play(); } else { TimeSpan delta = DateTime.Now.Subtract(alarmStarted.Value); // If the warning time has elapsed, start the welders if (delta.TotalSeconds > (soundLength - .9)) { ITerminalAction action; action = speaker.GetActionWithName("OnOff_On"); action.Apply(speaker); alarmStarted = DateTime.Now; speaker.Play(); } } } else { alarmStarted = null; speaker.Stop(); } }
public void setSound(IMySoundBlock speaker, bool value) { speakerGroup.GetBlocksOfType <IMySoundBlock>(speakerList); speaker.SelectedSound = soundName; speaker.LoopPeriod = loopTime; if (value) { if (endLoop == null) { ITerminalAction action; action = speaker.GetActionWithName("OnOff_On"); action.Apply(speaker); endLoop = DateTime.Now.AddSeconds(loopTime); speaker.Play(); } else { if (endLoop <= DateTime.Now) { ITerminalAction action; action = speaker.GetActionWithName("OnOff_On"); action.Apply(speaker); endLoop = DateTime.Now; speaker.Play(); } } } else { endLoop = null; speaker.Stop(); } }