Notifications.PlaySound Exception

Created at 22 Jun 2022, 21:03
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GE

gennimatas

Joined 19.09.2018

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)
        {
        }

    }
}

 


@gennimatas
Replies

firemyst
24 Jun 2022, 05:40 ( Updated at: 21 Dec 2023, 09:22 )

RE:

gennimatas said:

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)
        {
        }

    }
}

 

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