コード例 #1
0
        /// <summary>
        /// Open the audio reader.
        /// </summary>
        private void OpenReader()
        {
            if (!_internalStream)
            {
                _audioReader = new AudioReader(_audioStream, _audioFormat);
            }
            else
            {
                _audioReader = new AudioReader(_filename);
            }

            // Get the initial values of the stream.
            _duration = _audioReader.TotalTime;
        }
コード例 #2
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                Stop();

                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    if (_buffers != null)
                    {
                        for (int n = 0; n < _buffers.Length; n++)
                        {
                            if (_buffers[n] != null)
                            {
                                _buffers[n].Dispose();
                            }
                        }
                    }

                    lock (_waveOutLock)
                    {
                        WaveInterop.waveOutClose(_hWaveOut);
                    }

                    if (_audioReader != null)
                    {
                        _audioReader.Dispose();
                    }

                    // If the stream was created internally.
                    if (_internalStream)
                    {
                        if (_audioStream != null)
                        {
                            _audioStream.Dispose();
                        }
                    }

                    // Close the callback.
                    _callbackInfo.Disconnect();
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If the stream was created internally.
                _buffers     = null;
                _audioReader = null;

                // If the stream was created internally.
                if (_internalStream)
                {
                    _audioStream = null;
                }
            }
        }