Пример #1
0
        private MCIResult SendMCICommand(string mciCommand, int retLen)
        {
            var           mciResult = new MCIResult();
            StringBuilder ret       = null;

            if (retLen > 0)
            {
                ret = new StringBuilder(retLen);
            }

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(mciCommand, ret, retLen, IntPtr.Zero);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
            {
                mciResult.ReturnMessage = ret.ToString();
            }
            else
            {
                mciResult.ReturnMessage = string.Empty;
            }

            return(mciResult);
        }
Пример #2
0
        private MCIResult SendMCICommand(string mciCommand, int retLen)
        {
            var mciResult = new MCIResult();
            StringBuilder ret = null;

            if (retLen > 0)
                ret = new StringBuilder(retLen);

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(mciCommand, ret, retLen, IntPtr.Zero);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
                mciResult.ReturnMessage = ret.ToString();
            else
                mciResult.ReturnMessage = string.Empty;

            return mciResult;
        }
Пример #3
0
        private static MCIResult ProcessMCIRequest(MCIRequest request, IntPtr hwndHandle = new IntPtr())
        {
            var           mciResult = new MCIResult();
            StringBuilder ret       = null;

            if (request.retLen > 0)
            {
                ret = new StringBuilder(request.retLen);
            }

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(request.MCICommand, ret, request.retLen, hwndHandle);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
            {
                mciResult.ReturnMessage = ret.ToString();
            }
            else
            {
                mciResult.ReturnMessage = string.Empty;
            }

            if (mciResult.IsError())
            {
                if (Error != null)
                {
                    Error(new MCIErrorEventArgs(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage));
                }

                if (MCIErrorsThrowExceptions)
                {
                    throw new MediaPlayerException(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage);
                }
            }

#if DEBUG
            Console.WriteLine(string.Format("Sent at: {4}   Tick Count: {0}   Command: {1}   Result: {2} '{3}'",
                                            Environment.TickCount,
                                            request.MCICommand,
                                            mciResult.ReturnValue.ToString(),
                                            mciResult.ReturnMessage,
                                            request.Tick));
#endif

            return(mciResult);
        }
Пример #4
0
        private void ThreadedMCIConsumer()
        {
            // as this is a background-thread, the loop exits
            // when the thread is aborted from outside.
            while (true)
            {
                lock (_monitorLock)
                {
                    // wait for release of _monitorLock object;
                    // when this statement exits, a new mciCommand has been issued
                    Monitor.Wait(_monitorLock);

                    // the object has been released, so make the mci call
                    // from this thread and put the return value into the
                    // _syncMciResult field
                    _syncMciResult = SendMCICommand(_syncMciCommand, _syncMciRetLen);

                    // tell the other thread that a result has been obtained
                    Monitor.Pulse(_monitorLock);    // this exits the Monitor.Wait(_monitorLock) command on the other thread
                }
            }
        }
Пример #5
0
        private static MCIResult ProcessMCIRequest(MCIRequest request, IntPtr hwndHandle = new IntPtr())
        {
            var mciResult = new MCIResult();
            StringBuilder ret = null;

            if (request.retLen > 0)
                ret = new StringBuilder(request.retLen);

            // send the command string to the MCI
            mciResult.ReturnValue = mciSendString(request.MCICommand, ret, request.retLen, hwndHandle);

            // if an error was returned, raise the event, and throw exception if appropriate
            if (mciResult.IsError())
            {
                var buffer = new StringBuilder(128);
                mciGetErrorString(mciResult.ReturnValue, buffer, 128);
                ret = buffer;
            }

            if (ret != null)
                mciResult.ReturnMessage = ret.ToString();
            else
                mciResult.ReturnMessage = string.Empty;

            if (mciResult.IsError())
            {
                if (Error != null)
                    Error(new MCIErrorEventArgs(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage));

                if (MCIErrorsThrowExceptions)
                    throw new MediaPlayerException(request.MCICommand, mciResult.ReturnValue, mciResult.ReturnMessage);
            }

            #if DEBUG
            Console.WriteLine(string.Format("Sent at: {4}   Tick Count: {0}   Command: {1}   Result: {2} '{3}'",
                Environment.TickCount,
                request.MCICommand,
                mciResult.ReturnValue.ToString(),
                mciResult.ReturnMessage,
                request.Tick));
            #endif

            return mciResult;
        }
Пример #6
0
        private void ThreadedMCIConsumer()
        {
            // as this is a background-thread, the loop exits
            // when the thread is aborted from outside.
            while (true)
            {
                lock (_monitorLock)
                {
                    // wait for release of _monitorLock object;
                    // when this statement exits, a new mciCommand has been issued
                    Monitor.Wait(_monitorLock);

                    // the object has been released, so make the mci call
                    // from this thread and put the return value into the
                    // _syncMciResult field
                    _syncMciResult = SendMCICommand(_syncMciCommand, _syncMciRetLen);

                    // tell the other thread that a result has been obtained
                    Monitor.Pulse(_monitorLock);    // this exits the Monitor.Wait(_monitorLock) command on the other thread
                }
            }
        }