Notifications.PlaySound, do I made any mistake in the code?
            
                 26 Nov 2022, 19:56
            
                    
Hello,
Anyone had used Notifications.PlaySound successfully? I tried both .mp3 and .wav to play in cBots, but neither can I do it.
Ver 4.4.19 and 4.2.22 were tested. The exception message from the log is as below:

Please advise, thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.FullAccess)]
    public class NewcBot : Robot
    {
        protected override void OnStart()
        {
            Notifications.PlaySound(@"D:\Cashing.wav");
        }
        protected override void OnTick()
        {
        }
        protected override void OnStop()
        {
        }
    }
}
Replies
                     Capt.Z-Fort.Builder
                     28 Nov 2022, 13:55
                                            ( Updated at: 21 Dec 2023, 09:23 )
                                    
RE:
Here is the only message I got from the log:
My system installed another media player PotPlayer, I hope this won't matter the c# to playsound.

Thanks, if any advice.
PanagiotisChar said:
Hi there,
Yes and they work fine. Do you get any exceptions in the log?
Need help? Join us on Telegram
Need premium support? Trade with us
@Capt.Z-Fort.Builder
                     firemyst
                     09 Dec 2022, 04:04
                                    
I found the best way to play sounds is to use the built in system sounds, and then assign your wave file to the system sound through the Control Panel.
Sample code:
if (AlertSoundToPlay == AlertSoundsOptions.Exclamation)
                                System.Media.SystemSounds.Exclamation.Play();
                            else if (AlertSoundToPlay == AlertSoundsOptions.Asterisk)
                                System.Media.SystemSounds.Asterisk.Play();
                            else if (AlertSoundToPlay == AlertSoundsOptions.Beep)
                                System.Media.SystemSounds.Beep.Play();
                            else if (AlertSoundToPlay == AlertSoundsOptions.Hand)
                                System.Media.SystemSounds.Hand.Play();
                            else if (AlertSoundToPlay == AlertSoundsOptions.Question)
                                System.Media.SystemSounds.Question.Play();
                            else
                                System.Media.SystemSounds.Exclamation.Play();
@firemyst

PanagiotisChar
28 Nov 2022, 09:30
Hi there,
Yes and they work fine. Do you get any exceptions in the log?
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar