Features, discussions, tips, tricks, questions, problems and feedback

A media player control for custom sounds

To configure a custom sound, the MediaPlayer custom control can be used to play any MP3 media file or other sound file. There are a few steps to use this control:

  1. Download the control here: mediaplayer files
  2. Go to the “plugins” folder: C:\Program Files (x86)\Adroit Technologies\Adroit\SmartUI\plugins (there is a similar folder for MAPS installs)
  3. Create a “MediaPlayer” folder in the plugins folder and copy the files in there:
  4. Add the control in the Designer toolbox, by right clicking on the toolbox and selecting “Add Controls”:

  5. Drop the control on to a form:
  6. Drive the media player control via it’s properties:

The “MusicFileToOpen” property must include the FULL PATH TO THE FILE i.e. C:\MYSOUNDS\FILE.MP3 or something similar.

If the “StartPlaying” property is set to True, it will start playing the media file.

1 Like

The source code for this control can be downloaded here:

media player source

Please note that this is an unsupported control and is used as an example of using custom controls inside the Smart UI.

To Add Code in your Graphic Form To Play a sound when there are Unacked Alarms, you can use the following C# Code

Add the MediaControl as per above and set the Visibility Proppery to false.
Add the full path name of the sound file to the MusicFileToOpen Property.
( Choose a sound file that is less than 2 seconds long)

Add a timer control. and Set the Following Properties
name = timAlarm
Enabled = true
Interval = 2000 ( or the amount of time you want the sound to repeat)

Create a graphic Form Event Handler by Double-clicking on the Timer Control.
Add the name of the function “playSoundOnAlarm();” in the Tick event Function:

private void timAlarm_Tick(System.Object sender, System.EventArgs e)
{
	playSoundOnAlarm();
}


private void playSoundOnAlarm()
		{
			try
			{
				string tagName = "Adroit.Alarm.defaultAlarmAgent.numAlarmsUnacked";
				DataElement a1 = VIZNET.Shared.DataElements.Engine.DataElementEngine.NewDataElement(tagName);
				DataElementCollection dec = VIZNET.Shared.DataElements.Engine.DataElementEngine.NewDataElementCollection();
				dec.Add(a1);
				MethodReturnInfo info = MyConnection.ReadDataElements(dec);
				int UnackedAlarms = 0;

				DataElementCollection collectionReturned = info.ReturnObject as DataElementCollection;
				foreach (DataElement de in collectionReturned.Values)
				{
					UnackedAlarms = Convert.ToInt32(de.Value);
				}

				if (UnackedAlarms > 0)
				{
					mediaControl.StartPlaying = true;
				}
				
			}
			catch (Exception ex)
			{
			   
			}
		}
2 Likes

I updated the controls with RepeatSound and RepeatInterval properties. If you set the RepeatSound property to true and the RepeatInterval to the 5000 milliseconds then the sound will repeat every 5 seconds.
Controls:
UpdatedSmartUIMediaPlayer.zip (112.6 KB)

SourceCode:
Updated smartuimediaplayer.zip (654.1 KB)

**The default values on the controls are set to repeat the sound every 2500 milliseconds or 2.5 seconds

2 Likes

A new rebuilt version for Adroit 10.0.5.x can be found here:

SmartUIMediaPlayer.zip (116.7 KB)

NB: Please be aware this is an unofficial and unsupported control.

1 Like