Example #1
0
      private mmStatus playSesssion(mmSessionDictionaryKeys flags, IntPtr lpData)
      {
         if (_hSession == IntPtr.Zero)
            return mmStatus.MM_STS_LIB_ERROR_INVALID_STATE;

         if (lpData != IntPtr.Zero) // else a re-connect on error case using existing params
         {
            _parms.Play.PlayParms = (MM_CLIENT_PLAY)Marshal.PtrToStructure(lpData, typeof(MM_CLIENT_PLAY));
            if (_parms.Play.PlayParms.Size == (Marshal.SizeOf(typeof(MM_CLIENT_PLAY))))
            {
               _parms.Play.StartTime = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_PLAY)));
               _parms.Play.EndTime = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_PLAY)) + (2 * (_parms.Play.StartTime.Length + 1)));
            }
            else
               return mmStatus.MM_STS_SRC_ERROR_INCOMPATIBLE_API;
         }

         if (string.IsNullOrEmpty(_parms.Play.StartTime))
            _parms.Play.PlayParms.PStartTime = IntPtr.Zero;
         else
            _parms.Play.PlayParms.PStartTime = (IntPtr)Marshal.StringToHGlobalAnsi(_parms.Play.StartTime);

         if (string.IsNullOrEmpty(_parms.Play.EndTime))
            _parms.Play.PlayParms.PEndTime = IntPtr.Zero;
         else
            _parms.Play.PlayParms.PEndTime = (IntPtr)Marshal.StringToHGlobalAnsi(_parms.Play.EndTime);

         mmStatus sts = mmMethods.mmClientPlay(_hSession, ref _parms.Play.PlayParms);

         if (_parms.Play.PlayParms.PStartTime != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Play.PlayParms.PStartTime);
         if (_parms.Play.PlayParms.PEndTime != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Play.PlayParms.PEndTime);

         return sts; // any play error makes its way back via the callback
      }
Example #2
0
      private mmStatus openSesssion(mmSessionDictionaryKeys flags, IntPtr lpData)
      {
         if (_hSession != IntPtr.Zero)
            return mmStatus.MM_STS_LIB_ERROR_INVALID_STATE;

         if (lpData != IntPtr.Zero) // else a re-connect on error case using existing params
         {
            _parms.Open.OpenParms = (MM_CLIENT_OPEN)Marshal.PtrToStructure(lpData, typeof(MM_CLIENT_OPEN));
            if (_parms.Open.OpenParms.Size == (Marshal.SizeOf(typeof(MM_CLIENT_OPEN))))
            {
               _parms.Open.URL = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)));
               _parms.Open.UserName = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)) + (2 * (_parms.Open.URL.Length + 1)));
               _parms.Open.PassWord = MMInterop.PtrToString(lpData + Marshal.SizeOf(typeof(MM_CLIENT_OPEN)) + (2 * ((_parms.Open.URL.Length + 1) + (_parms.Open.UserName.Length + 1))));
            }
            else
               return mmStatus.MM_STS_SRC_ERROR_INCOMPATIBLE_API;
         }
         
         string basicAuth = _parms.Open.URL;
         if( (uint)flags != 0x80000000) // playlist case
            _windowParent.LockPaintSessionStatus("Opening URL: " + _parms.Open.URL);

         _windowParent.LockSetSessionWindowText(_parms.Open.URL);

         if (!string.IsNullOrEmpty(_parms.Open.UserName))
         {
            var index = _parms.Open.URL.IndexOf("://");
            if (index != -1)
               basicAuth = basicAuth.Insert(index + 3, _parms.Open.UserName + ":" + _parms.Open.PassWord + "@");
         }

         _parms.Open.OpenParms.HWnd = _windowParent.GetHWND();

         // account for UTF8 encoded data
         int len = Encoding.UTF8.GetByteCount(basicAuth);
         byte[] utf8Bytes = new byte[len + 1];
         Encoding.UTF8.GetBytes(basicAuth, 0, basicAuth.Length, utf8Bytes, 0);
         _parms.Open.OpenParms.PURL = Marshal.AllocHGlobal(utf8Bytes.Length); 
         Marshal.Copy(utf8Bytes, 0, _parms.Open.OpenParms.PURL, utf8Bytes.Length);

         if (_parms.Open.Reserved != 0)
         {
            _parms.Open.OpenParms.PReserved = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
            Marshal.WriteInt32(_parms.Open.OpenParms.PReserved, 0, ((int)_parms.Open.Reserved));
         }
         else
            _parms.Open.OpenParms.PReserved = IntPtr.Zero;

         mmStatus sts = mmMethods.mmClientOpen(out _hSession, ref _parms.Open.OpenParms);
         if (sts != mmStatus.MM_STS_NONE)
         {
            _windowParent.LockPaintSessionStatus($"STATUS 0x{sts:X} Opening URL: " + _parms.Open.URL);
            _windowParent._watchDog.Enabled = true;
            // start a fresh
            _parms.Play.StartTime = null;
            _parms.Play.EndTime = null;
         }
         else
            _windowParent.LockPaintSessionStatus("");

         if (_parms.Open.OpenParms.PReserved != IntPtr.Zero)
            Marshal.FreeHGlobal(_parms.Open.OpenParms.PReserved);
         
         Marshal.FreeHGlobal(_parms.Open.OpenParms.PURL);
         return sts;
      }