View Full Version : Playing 2 sound files sequentially
mason
07-15-2008, 10:24 AM
How to play 2 sound files sequentially ?
I tried with Alert() and PlaySound() with no luck. I can only hear the last sound file.
Basically what I want to do is Play/Alert 1st sound file and after it finishes, it then Play/Alert 2nd sound file.
NinjaTrader_Ray
07-15-2008, 11:35 AM
You would have to code your own way to play sounds files using C# language and play them synchronously. NT methods are asynchronous.
NinjaTrader_Dierk
07-15-2008, 12:06 PM
To clarify: Ray's recommendation comes at the expense that NT would be locked up (=non responsive) if you played sound files synchronously. That's why NinjaScript plays it asynchronously.
A different approach would be recording the sound files as one and play that by PlaySound().
mason
07-15-2008, 08:44 PM
Thanks for the hint, I am going after playing C# first, because combination will create lots of files.
But, it would be great to have option to choose between synch and asynch.
mason
07-15-2008, 10:52 PM
This is what I do, the keyword would be PlaySync.
using System.Media;
using System.IO;
private SoundPlayer player = new SoundPlayer();
private string directory;
directory = Directory.GetParent(Environment.CurrentDirectory). FullName + "\\sounds\\";
player.SoundLocation = directory+"sound.wav";
player.PlaySync();
NinjaTrader_Dierk
07-16-2008, 12:07 AM
Again: we recommend NOT doing that, since it will lock up NT while the sound file it played. That's why we won't provide an option to play sound files synchronized.
mason
07-16-2008, 05:22 AM
Yes, I can see that how the performance degrades, but I keep my sound files very small and very short, also I only use this for the 1st sound file, the 2nd sound file is still using Alert and it only triggers every 20 seconds.
Jbarn
07-17-2008, 02:50 PM
Again: we recommend NOT doing that, since it will lock up NT while the sound file it played. That's why we won't provide an option to play sound files synchronized.
Is there sample code for playing a sound file asynchronously?
NinjaTrader_Ray
07-17-2008, 02:57 PM
We do not have one.