Esempio n. 1
0
 public long GetPosition()
 {
     if (Monitor.TryEnter(_lockObject, 10))
     {
         try
         {
             if (_waveOutHandle == IntPtr.Zero)
             {
                 return(0);
             }
             else
             {
                 MmTime mmTime = new MmTime();
                 mmTime.wType = MmTime.TIME_MS;
                 NativeMethods.waveOutGetPosition(_waveOutHandle, out mmTime, (uint)Marshal.SizeOf(mmTime));
                 return(mmTime.ms);
             }
         }
         finally
         {
             Monitor.Exit(_lockObject);
         }
     }
     return(0);
 }
Esempio n. 2
0
        public long GetPosition()
        {
            MmTime mmTime = new MmTime();

            mmTime.wType = 4U;
            MmException.Try(
                WaveInterop.waveInGetPosition(this.waveInHandle, out mmTime, Marshal.SizeOf <MmTime>(mmTime)),
                "waveInGetPosition");
            return(mmTime.wType == 4U
                ? (long)mmTime.cb
                : throw new Exception(string.Format("waveInGetPosition: wType -> Expected {0}, Received {1}",
                                                    (object)4, (object)mmTime.wType)));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the current position in bytes from the wave output device.
        /// (n.b. this is not the same thing as the position within your reader
        /// stream - it calls directly into waveOutGetPosition)
        /// </summary>
        /// <returns>Position in bytes</returns>
        public long GetPosition()
        {
            lock (waveOutLock)
            {
                var mmTime = new MmTime();
                mmTime.wType = MmTime.TIME_BYTES; // request results in bytes, TODO: perhaps make this a little more flexible and support the other types?
                MmException.Try(WaveInterop.waveOutGetPosition(hWaveOut, out mmTime, Marshal.SizeOf(mmTime)), "waveOutGetPosition");

                if (mmTime.wType != MmTime.TIME_BYTES)
                {
                    throw new Exception(string.Format("waveOutGetPosition: wType -> Expected {0}, Received {1}", MmTime.TIME_BYTES, mmTime.wType));
                }

                return(mmTime.cb);
            }
        }
Esempio n. 4
0
        public static long GetPositionBytes(IntPtr hWaveOut, object lockObject)
        {
            lock (lockObject)
            {
                var mmTime = new MmTime();
                mmTime.wType = MmTime.TIME_BYTES; // request results in bytes, TODO: perhaps make this a little more flexible and support the other types?
                MmException.Try(WaveInterop.waveOutGetPosition(hWaveOut, ref mmTime, Marshal.SizeOf(mmTime)), "waveOutGetPosition");

                if (mmTime.wType != MmTime.TIME_BYTES)
                {
                    throw new Exception(
                              $"waveOutGetPosition: wType -> Expected {MmTime.TIME_BYTES}, Received {mmTime.wType}");
                }

                return(mmTime.cb);
            }
        }
Esempio n. 5
0
 public static extern MmResult waveOutGetPosition(IntPtr hWaveOut, out MmTime mmTime, int uSize);
Esempio n. 6
0
 public static extern int waveOutGetPosition(IntPtr hWaveOut, ref MmTime lpInfo, int uSize);