/// <summary> /// Shows the dialog if necessary and returns a new playback position in milliseconds. /// </summary> /// <param name="videoFileStatistic">A VideoFileStatistic class instance to be used to initialize the dialog from.</param> /// <returns>A playback position in milliseconds.</returns> public static long Execute(VideoFileStatistic videoFileStatistic) { // if the saved playback position is zero or more than 99 percent was played last time just return 0.. // decrease 5 seconds from the position for "a human/a media consuming entity" to catch/remember something of the previous moment.. if (videoFileStatistic.Position - 5000 <= 0 || videoFileStatistic.PlayBackPercentage >= 99.0) { return(0); } // the given VideoFileStatistic class instance requires the dialog to be shown.. so create a SelectPlaybackPositionDialog.. FormDialogSelectPlaybackPosition selectPlaybackPositionDialog = new FormDialogSelectPlaybackPosition(); // a N value of a milliseconds to ticks (100-nanosecond units) = multiply by 100 * 100.. TimeSpan timeSpan = new TimeSpan(videoFileStatistic.Position * 100 * 100); // give the statistics for the form.. // .. and decrease 5 seconds from the position for "a human/a media consuming entity" to catch/remember something of the previous moment.. selectPlaybackPositionDialog.Tag = videoFileStatistic.Position - 5000; // set the playback position for to the button "Continue playback from position N".. selectPlaybackPositionDialog.btContinue.Text = string.Format(selectPlaybackPositionDialog.btContinue.Tag.ToString(), timeSpan.ToString(@"hh\:mm\:ss")); // show the dialog.. selectPlaybackPositionDialog.ShowDialog(); // return the playback position the user selected by return(selectPlaybackPositionDialog.returnPlaybackPosition); }
private void VlcControl_Playing(object sender, VlcMediaPlayerPlayingEventArgs e) { if (file != null && !statisticsLoaded) { statisticsLoaded = true; statistic = Database.GetStatistic(file.FullName); } }
/// <summary> /// An event that is raised by the VisualFileBrowser control when a custom image describing an item in the list. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A VisualFileBrowser.FileOrDirectorySelectedEventArgs class instance.</param> private void vfbSelectFileOrDir_GetCustomItemImage(object sender, VPKSoft.VisualFileBrowser.VisualFileBrowser.FileOrDirectorySelectedEventArgs e) { if (e.IsFile) // if a custom image for a file is requested.. { Database.SetFile(e.Path); // first ensure the file is added to the database.. // Get statistics for the file from the database.. VideoFileStatistic statistic = Database.GetStatistic(e.Path); if (statistic.Played) // A video file is watched so give an image which indicates a tick or check.. { e.Image = Properties.Resources.tick; } else if (statistic.Position > 0) // A part of the video file is watched so give it an image of a quarter of a ball.. { e.Image = Properties.Resources.not_whole; } else // no reasonable images to give so give it nothing.. { e.Image = null; } } }
private bool cursorHidden = false; // A value indicating whether the mouse cursor was hidden // a timer to monitor the playback, etc.. private void tmMain_Tick(object sender, EventArgs e) { if (closeForm) // The VLC library has launched a signal from an event that the form can now be closed. { tmMain.Enabled = false; // Disable the timers from screwing up the form close.. tmWindRewind.Enabled = false; if (file != null) // only update if a file was playing.. (an exception might occur) { Database.UpdateFile(file.FullName, vlcControl.Time, vlcControl.Length, IsWacthed, Volume); } Close(); // Close the form. // raise the event if subscribed.. PlaybackClosed?.Invoke(this, new FormPlayerCloseEventArgs() { FileInfo = file }); return; // nothing to do here.. } if (statisticsLoaded && statistic != null) { if (statistic.Position > 0) // if there is anything to adjust to the playback position as it's good to remember it.. { vlcControl.Playing -= VlcControl_Playing; // unsubscribe some events.. // calculate the percentage of the saved playback position.. double positionPercentage = ((double)statistic.Position * 100 / (double)vlcControl.Length); if (positionPercentage >= 99.50) // .. and if it exceeds 99.5%, the jump to the start so the playback won't stop prematurely.. { vlcControl.Time = 0; // .. 99.5 or more means a position of 0.. } else { vlcControl.Time = statistic.Position; // ..otherwise continue the playback from the saved position.. } sliderVolume.Scroll -= sliderVolume_Scroll; // unsubscribe some more events.. sliderVolume.Value = (int)statistic.Volume; // set the saved to the volume slider.. vlcControl.Audio.Volume = (int)statistic.Volume; // set the saved volume to the actual playback track.. sliderVolume.Scroll += sliderVolume_Scroll; // subscribe the events back.. vlcControl.Playing += VlcControl_Playing; // and subscribe more events back.. } statisticsLoaded = false; // no forget that any statistics were ever loaded.. statistic = null; // .. otherwise an endless loop might occur. } if (secondsCount > 10) // Hide the annoying mouse cursor.. { tmMain.Enabled = false; // disable the timer while processing.. if (!cursorHidden && popupHidden) { Cursor.Hide(); cursorHidden = true; } secondsCount = 0; HidePopDown(); // we don't want to see this either as the mouse can be far-far away.. when sitting on the couch :-( tmMain.Enabled = true; // ..enable the timer after processed } tmMain.Enabled = false; // disable the timer while processing.. secondsCount++; // increase the mouse cursor hide counter (seconds).. // Show the current playback time TimeSpan timeSpanTotal = new TimeSpan(0, 0, (int)vlcControl.Length / 1000); TimeSpan timeSpanPosition = new TimeSpan(0, 0, (int)vlcControl.Time / 1000); lbTimeValue.Text = timeSpanPosition.ToString(@"hh\:mm\:ss") + "/" + timeSpanTotal.ToString(@"hh\:mm\:ss"); SetTimeSliderPosition(); // Sets the slider position to match the playback position.. tmMain.Enabled = true; // ..enable the timer after processed }