示例#1
0
        /// <summary>
        /// Load the media file.
        /// </summary>
        /// <param name="mediaString">The media file to load.</param>
        /// <param name="mediaIndex">The media index type to load.</param>
        private void LoadMedia(string mediaString, int mediaIndex)
        {
            // If a media string has been selected.
            if (!String.IsNullOrEmpty(mediaString))
            {
                try
                {
                    if (_player == null)
                    {
                        // Create the player.
                        _player = new Nequeo.Directx.MediaPlayer();
                        _player.PlayerWindow = this.panelMediaDisplay;

                        _timer          = new System.Timers.Timer(2000);
                        _timer.Elapsed += _timer_Elapsed;

                        // Open the correct media type.
                        switch (mediaIndex)
                        {
                        case 1:
                            // Open the media file.
                            _player.Open(mediaString);
                            break;

                        case 0:
                        default:
                            // Open the media file.
                            _player.Open(mediaString);
                            break;
                        }

                        // Get the duration.
                        _duration          = _player.Duration;
                        labelDuration.Text = TimeSpan.FromSeconds(_duration).ToString().Substring(0, 8);

                        // Enable controls.
                        EnabledControls(true);
                        this.AllowDrop = false;
                    }
                }
                catch
                {
                    _player.Close();
                    _player.Dispose();
                    _player = null;

                    if (_timer != null)
                    {
                        // Stop the timer.
                        _timer.Enabled = false;
                        _timer.Dispose();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Closes the media player and releases all resources.
        /// </summary>
        public void CloseMedia()
        {
            if (_player != null)
            {
                // Close the media player.
                _player.Stop();
                _player.Close();
                _player.Dispose();

                if (_timer != null)
                {
                    // Stop the timer.
                    _timer.Enabled = false;
                    _timer.Dispose();
                }
            }

            _player = null;
            _timer  = null;
        }
示例#3
0
        /// <summary>
        /// Close the player.
        /// </summary>
        private void ClosePlayer()
        {
            if (_player != null)
            {
                labelTime.Text     = "00:00:00";
                labelDuration.Text = "00:00:00";
                EnabledOnCloseControls(false);

                // Close the media player.
                _player.Close();
                _player.Dispose();

                if (_timer != null)
                {
                    // Stop the timer.
                    _timer.Enabled = false;
                    _timer.Dispose();
                }
            }

            _player        = null;
            _timer         = null;
            this.AllowDrop = true;
        }