Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

PlaySound function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PlaySound function

    Hi,


    I see an example:

    PlaySound(@":\Myfile.wav")


    1. could you please explain what the @ means here?

    2. Does the function also work without the @ ?

    3. Is it possible to specify syncronous or asyncroneous playing?

    4. Will PlaySound queue consecutive play requests even if a request comes in
    while the previous sound is still playing?


    Best regards

    Andreas

    #2
    The @ forces it to a specific directory. If you do not use the @ it will go from the default directory mapping. I would just use the @ since it makes things simply to understand exactly where the file is located.

    Not sure what you mean synchronous or asynchronous playing. It will play a sound when the function is called.

    I believe it should. It may just play over the prior sound as the new call is reached. You could give it a try and see if it does what you want by calling PlaySound twice within a single OnBarUpdate().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      So ,

      the NT PlaySound function is syncroneous. This means that calling PlaySound from within time critical code like OnMarketData will cause NT to be unresponsive (=hangs) for the time of the playing of the Sound file.

      For who wants to go to an async version, here a code snippet to start with:

      good luck

      Andreas



      ----------------------------------------------

      using System.IO;

      public class Sound
      {
      private string m_fileName;

      private enum Flags
      {
      SND_SYNC = 0x0000,
      SND_ASYNC = 0x0001,
      SND_NODEFAULT = 0x0002,
      SND_LOOP = 0x0008,
      SND_NOSTOP = 0x0010,
      SND_NOWAIT = 0x00002000,
      SND_FILENAME = 0x00020000,
      SND_RESOURCE = 0x00040004

      }

      [System.Runtime.InteropServices.DllImport("winmm.DL L", EntryPoint = "PlaySound", SetLastError = true)]
      private static extern bool PlaySound(string szSound, System.IntPtr hMod, Flags flags);


      /// <summary>
      /// Construct the Sound object to play sound data from the specified file.
      /// </summary>
      public void SoundInNTSoundsDir(string filename){
      System.IO.DirectoryInfo directoryInfo=
      System.IO.Directory.GetParent(System.IO.Directory. GetCurrentDirectory());
      m_fileName=directoryInfo.ToString();
      m_fileName+="\\sounds\\";
      m_fileName+=filename;
      }
      public Sound(string fileName)
      {
      m_fileName = fileName;
      }

      /// <summary>
      /// Play the sound
      /// </summary>
      public void Play()
      {
      // if a file name has been registered, call PlaySound,

      if (m_fileName != null)
      PlaySound(m_fileName, IntPtr.Zero, Flags.SND_ASYNC | Flags.SND_FILENAME);
      }
      }

      main(){

      Sound S;
      S = new Sound("");
      S.SoundInNTSoundsDir("Alert1.wav");
      S.Play();

      }

      Comment


        #4
        I don't seem to have a problem with PlaySound besides the constant barrage of sound. I have 3 charts with two types of PlaySound triggers with two different sounds each. Sometimes they are all going at once with a possible six sounds. For some reason I don't notice any slowdown from that.
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          I take that back. When the sound is a continous buzzing, the Dom freezes momentarily. I will have to check out your solution.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment


            #6
            I found this site helpful with this: http://www.pinvoke.net/default.aspx/...nd.html?diff=y

            Shows simple .NET code toward the bottom too.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lightsun47, Today, 03:51 PM
            0 responses
            2 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            8 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            41 views
            0 likes
            Last Post futtrader  
            Started by Option Whisperer, Today, 09:55 AM
            1 response
            12 views
            0 likes
            Last Post bltdavid  
            Started by port119, Today, 02:43 PM
            0 responses
            8 views
            0 likes
            Last Post port119
            by port119
             
            Working...
            X