/// <summary> /// Open the media. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonOpen_Click(object sender, EventArgs e) { if (_player == null) { // Create the player. _player = new Nequeo.Media.MediaPlayer(); // Set the certificate filter. openFileDialogMain.Filter = "Media Files (*.nva)|*.nva"; // Get the file name selected. if (openFileDialogMain.ShowDialog() == DialogResult.OK) { _timer = new System.Timers.Timer(2000); _timer.Elapsed += _timer_Elapsed; // Open the media file. _player.Open(openFileDialogMain.FileName); // Get the duration. _duration = _player.Duration.TotalSeconds; labelDuration.Text = TimeSpan.FromSeconds(_duration).ToString().Substring(0, 8); // Enable controls. EnabledControls(true); } else { _player.Close(); _player = null; } } }
/// <summary> /// Closes the media player and releases all resources. /// </summary> public void CloseMedia() { if (_player != null) { // Close the media player. _player.Stop(); _player.Close(); if (_timer != null) { // Stop the timer. _timer.Enabled = false; _timer.Dispose(); } } _player = null; _timer = null; }