Esempio n. 1
0
        public override int RenderVisualization()
        {
            if (VisualizationWindow.InvokeRequired)
            {
                ThreadSafeRenderDelegate d = new ThreadSafeRenderDelegate(RenderVisualization);
                return((int)VisualizationWindow.Invoke(d));
            }

            RECT rect = new RECT();

            rect.left   = 0;
            rect.top    = 0;
            rect.right  = VisualizationWindow.Width;
            rect.bottom = VisualizationWindow.Height;

            TimedLvl.waveform  = new byte[2048];
            TimedLvl.frequency = new byte[2048];
            TimedLvl.State     = (int)WMPInterop.AudioState.Playing;

            bool gotWaveData = GetWaveData(ref TimedLvl.waveform);
            bool gotfreqData = GetFftData(ref TimedLvl.frequency);

            IntPtr pTimedLevel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WMPInterop.TimedLevel)));

            Marshal.StructureToPtr(TimedLvl, pTimedLevel, false);

            int result = 0;

            result = WMPInterop.RenderWMP(pTimedLevel, ref rect);

            Marshal.FreeHGlobal(pTimedLevel);
            return(result);
        }
Esempio n. 2
0
    public override int RenderVisualization()
    {
      if (VisualizationWindow.InvokeRequired)
      {
        ThreadSafeRenderDelegate d = new ThreadSafeRenderDelegate(RenderVisualization);
        return (int)VisualizationWindow.Invoke(d);
      }

      RECT rect = new RECT();
      rect.left = 0;
      rect.top = 0;
      rect.right = VisualizationWindow.Width;
      rect.bottom = VisualizationWindow.Height;

      TimedLvl.waveform = new byte[2048];
      TimedLvl.frequency = new byte[2048];
      TimedLvl.State = (int)WMPInterop.AudioState.Playing;

      bool gotWaveData = GetWaveData(ref TimedLvl.waveform);
      bool gotfreqData = GetFftData(ref TimedLvl.frequency);

      IntPtr pTimedLevel = Marshal.AllocHGlobal(Marshal.SizeOf(typeof (WMPInterop.TimedLevel)));
      Marshal.StructureToPtr(TimedLvl, pTimedLevel, false);

      int result = 0;

      try
      {
        result = WMPInterop.RenderWMP(pTimedLevel, ref rect);
      }
      catch (AccessViolationException)
      {
        return result; // We could get an Access Violation when changing Vis
      }

      Marshal.FreeHGlobal(pTimedLevel);
      return result;
    }