Play Sound, simply one but no work
Play Sound, simply one but no work
15 Mar 2017, 13:47
Hi, I made a simply Indicator to test PlaySound function, but the sound do not play anymore in cAlgo or in cTrade
I add an instance in cAlgo and in log file I see err: Notification: PlaySound of 'C:\tada.wav' failed
I tried 3 diffrent files: test.mp3, test.wav and tada.wav from Windos system
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; using ccTest; using System.Windows.Forms; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { int i public override void Calculate(int index) { i++; Notifications.PlaySound("C:\\tada.wav"); ChartObjects.DrawText("x", "test " + i, StaticPosition.BottomLeft, Colors.Black); } } }
Replies
bogdan@devize.ro
16 Mar 2017, 11:09
Yes, this working well. But, i wonder, what is happen with Notifications.PlaySound?
Thank you for your hint
@bogdan@devize.ro
bogdan@devize.ro
16 Mar 2017, 11:36
RE:
tmc. said:
Make sure you have correct path to sound file. Notifications are working fine on my end.
Belive me, it is the simply path in the word: C:\tada.wav ... I have tried 10 diffrent path woth 3 diffrent sound files ... and I have run on 2 diffrent PCs
@bogdan@devize.ro
Jiri
16 Mar 2017, 11:47
Try this.
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NotificationTest : Indicator { protected override void Initialize() { Timer.Start(3); } protected override void OnTimer() { Notifications.PlaySound("C:\\Windows\\Media\\tada.wav"); } public override void Calculate(int index) { } } }
@Jiri
bogdan@devize.ro
16 Mar 2017, 11:51
Initialy, my code have a condition to play on a new bar, I do not want to play continuosly on each Calculate event, anyway, I do your test below and no sound was played
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class NewIndicator : Indicator { int i; public override void Calculate(int index) { if (IsLastBar) { i++; // System.Media.SoundPlayer player = new System.Media.SoundPlayer("C:\\Windows\\Media\\tada.wav"); Notifications.PlaySound("C:\\Windows\\Media\\tada.wav"); //player.Play(); ChartObjects.DrawText("x", "test " + i, StaticPosition.BottomLeft, Colors.Yellow); } } } }
@bogdan@devize.ro
bogdan@devize.ro
16 Mar 2017, 11:54
RE:
tmc. said:
Try this.
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NotificationTest : Indicator { protected override void Initialize() { Timer.Start(3); } protected override void OnTimer() { Notifications.PlaySound("C:\\Windows\\Media\\tada.wav"); } public override void Calculate(int index) { } } }
Yes, I have tried and your code too, no play...
@bogdan@devize.ro
bogdan@devize.ro
16 Mar 2017, 12:08
I have tried on a virtual machine, new windows insatlled, winth .net Framework 4.5 ...
@bogdan@devize.ro
SwapBridgeCapital
21 Jun 2017, 17:41
( Updated at: 21 Dec 2023, 09:20 )
Notification Play Sound does not work.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class NewIndicator : Indicator { int i; public override void Calculate(int index) { if (IsLastBar) { i++; System.Media.SoundPlayer player = new System.Media.SoundPlayer("C:\\calgo\\buy.wav"); player.Play(); ChartObjects.DrawText("x", "test " + i, StaticPosition.BottomLeft, Colors.Yellow); } } } }
I have tried the above code. Does not work.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class NewIndicator : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } protected override void Initialize() { // Initialize and create nested indicators Notifications.PlaySound("C:\\Users\\Asus\\Documents\\cAlgo\\Sources\\Robots\\buy.wav"); Notifications.PlaySound("C:\\Users\\Asus\\Documents\\cAlgo\\Sources\\Robots\\Buy.wav"); Notifications.PlaySound("C:\\calgo\\Buy.wav"); Notifications.PlaySound("C:\\calgo\\buy.wav"); } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... Notifications.PlaySound("C:\\Users\\Asus\\Documents\\cAlgo\\Sources\\Robots\\buy.wav"); Notifications.PlaySound("C:\\Users\\Asus\\Documents\\cAlgo\\Sources\\Robots\\Buy.wav"); Notifications.PlaySound("C:\\calgo\\Buy.wav"); Notifications.PlaySound("C:\\calgo\\buy.wav"); } } }
The above code does not work.
I have tried the old API - /api/reference/internals/inotifications/playsound
Notifications.PlaySound(@"C:\SampleDestination\SampleSound.mp3");
When using PlaySound(@"location") after compiling the code, It is automatically updated to
Notifications.PlaySound("C:\\SampleDestination\\SampleSound.mp3");
On WIndows10, with microsoft .net 4.5.1 framewrok and 4.6
I've also made my wav files into mp3 and the playsound still does not work. Every time the the calgo or cbot log file will say FAILED.
The previous member had issues in March 2017. Today , JUNE 2017. Still no support? solution? Please help community.
@SwapBridgeCapital
SwapBridgeCapital
22 Jun 2017, 06:14
Notification.PlaySound Error
[Parameter("Alert Buy Sound File", DefaultValue = "C:\\calgo\\buy.wav")] public string alertBuyFile { get; set; } //====== example to use within your code // if (UseNotify) { Notifications.PlaySound(alertBuyFile); } if (UsePlayer) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(alertBuyFile); player.Play(); }
The system.media.soundplayer is working. Until the Notifications is fixed, I have placed a Boolean in the code to enable the SoundPlayer.
@SwapBridgeCapital
SwapBridgeCapital
22 Jun 2017, 06:25
The issue looks to be within the cBot because the above code will work fine within an indicator but when applying the same function within a cBot, both methods above mentioned to play a sound file does not work. It fails to open the file as mentioned before. Can anyone explain why sound can work within an indicator and not a cbot? FullAccess is applied in both (indicator/cbot)
namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
@SwapBridgeCapital
SwapBridgeCapital
22 Jun 2017, 06:42
cBot code working now with the below code.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("Alert Sell Sound File", DefaultValue = "C:\\calgo\\sell.wav")] public string alertSellFile { get; set; } [Parameter("Alert Buy Sound File", DefaultValue = "C:\\calgo\\buy.wav")] public string alertBuyFile { get; set; } protected override void OnStart() { // Put your initialization logic here System.Media.SoundPlayer player = new System.Media.SoundPlayer(alertBuyFile); player.Play(); ChartObjects.DrawText("x", "test ", StaticPosition.BottomLeft, Colors.Yellow); } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
For the project that I am working on, when I attach a new Instance of my cBot, the PopUp box asks for permission, I accept the confirmation and the above code will play the sound. If I add another instance, it does not ask for the permission again ( FULLACCESS). Is this permission saved in memory? How to reset the permission? Removing all instances and re-adding them does not ask for the permission again.
@SwapBridgeCapital
... Deleted by UFO ...