Notifications.PlaySound Exception
Created at 22 Jun 2022, 21:03
GE
Notifications.PlaySound Exception
22 Jun 2022, 21:03
Following code is not playing on my win10 system after introduction of cTrader 4.2
Paths and files do exist.
Please advise.
Regards
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace testSound
{
[Indicator(IsOverlay = false, AccessRights = AccessRights.FileSystem)]
public class testSound : Indicator
{
[Parameter(DefaultValue = "tada")]
public string wav { get; set; }
protected override void Initialize()
{
IndicatorArea.MouseDown += IndicatorArea_MouseDown;
}
private void IndicatorArea_MouseDown(ChartMouseEventArgs obj)
{
var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
var path = System.IO.Path.Combine(windowsFolder, "Media", wav + ".wav");
Print(path);
// C:\WINDOWS\Media\tada.wav
Notifications.PlaySound(path);
// Notification: PlaySound of 'C:\WINDOWS\Media\tada.wav' failed. Exception message: 'Invalid URI: The URI is empty.'
path = @"C:\Windows\Media\Ring01.wav";
Print(path);
// C:\Windows\Media\Ring01.wav
Notifications.PlaySound(path);
// Notification: PlaySound of 'C:\Windows\Media\Ring01.wav' failed. Exception message: 'Invalid URI: The URI is empty.'
}
protected override void OnDestroy()
{
}
public override void Calculate(int index)
{
}
}
}
firemyst
24 Jun 2022, 05:40 ( Updated at: 21 Dec 2023, 09:22 )
RE:
gennimatas said:
If it helps, I use this instead:
System.Media.SystemSounds.Exclamation.Play();
and in Windows itself I assign the sound I want to the "Exclamation" sound from the Control Panel as follows:
@firemyst