Exemplo n.º 1
0
        public RemotedWindowsMediaPlayer()
        {
            // Create the Windows Media Player object
            Type   type     = Type.GetTypeFromCLSID(new Guid("6bf52a52-394a-11d3-b153-00c04f79faa6"));
            object instance = Activator.CreateInstance(type);

            //Get the IOleObject for Windows Media Player.
            IOleObject oleObject = instance as IOleObject;

            if (oleObject == null)
            {
                throw new Exception("Failed to get WMP OCX as an IOleObject?!");
            }

            //Set the Client Site for the WMP control.
            oleObject.SetClientSite(this as IOleClientSite);

            // Try and get the OCX as a WMP player
            m_instance = instance as IWMPPlayer4;
            if (m_instance == null)
            {
                Marshal.FinalReleaseComObject(instance);
                throw new Exception(string.Format("OCX is not an IWMPPlayer4! GetType returns '{0}'", m_instance.GetType()));
            }
        }
Exemplo n.º 2
0
        private void Dispose(bool disposing)
        {
            if (m_instance != null)
            {
#if DEBUG
                if (!disposing)
                {
                    Debug.Fail("Failed to dispose of RemoteWindowsMediaPlayer.");
                }
#endif
                m_player = null;
                Marshal.FinalReleaseComObject(m_instance);
                m_instance = null;
                GC.SuppressFinalize(this);
            }
        }