/// <summary> /// Opens a video file /// </summary> /// <param name="videoFile"></param> //public void OpenVideo(String videoFile) //{ // try // { // //Check if video filename is empty // fileToOpen = videoFile; // if (fileToOpen.Length < 1) // { // throw new AcException("Error opening video! Empty filename provided!"); // } // //Check the avsfile object to avoid memory leaks // if (avs != null) // { // avs.Dispose(); // } // //Check if video file exists // if (!File.Exists(fileToOpen)) // { // throw new AcException("Error opening video! Video file does not exist!"); // } // else // { // //Check if the video file is an AviSynth script // if (!AcHelper.GetFilename(fileToOpen, GetFileNameMode.ExtensionOnly, GetDirectoryNameMode.NoPath).Contains("avs")) // { // isAvisynth = false; // // AviSynthVideoSourceForm frm = new AviSynthVideoSourceForm(); // // frm.StartPosition = FormStartPosition.CenterParent; // // frm.ShowDialog(); // if (!frm.OKPressed) // { // //User aborted // return; // } // else // { // AviSynthFileCreator avsfc; // if (frm.OverrideFramerateChecked) // { // avsfc = new AviSynthFileCreator(fileToOpen, frm.SelectedAviSynthVideoProvider, frm.OverrideFramerate); // } // else // { // avsfc = new AviSynthFileCreator(fileToOpen, frm.SelectedAviSynthVideoProvider); // } // avisynthVideoProvider = frm.SelectedAviSynthVideoProvider; // fileToOpen = avsfc.AviSynthScriptFilename; // } // } // else // { // isAvisynth = true; // } // try // { // avs = AvsFile.OpenScriptFile(fileToOpen); // currentFrame = 0; // videoOpened = true; // fileOpened = fileToOpen; // videoData = new VideoPlayerUpdateData(avs); // updateVideoData(); // //acForm.UpdateGUI(videoData); // } // catch (Exception ex) // { // videoOpened = false; // throw new AcException("Error opening video!", ex); // } // } // } // catch (Exception ex) // { // throw new AcException("Error opening video!", ex); // } //} public void PlayVideo() { try { //Check if any video is opened if (!videoOpened) { throw new AcException("Error playing video! No Video opened!"); } //Set the flag videoPlaying = true; //Get the last valid video frame Int32 endPlayFrame = avs.Clip.NumberOfFrames - 1; //Get the frame duration Int32 frameDuration = Convert.ToInt32((Convert.ToDouble(avs.Clip.Rated) / Convert.ToDouble(avs.Clip.Raten)) * 1000.0); // Int32 sleepTime = 0; //Create timer Stopwatch actime = new Stopwatch(); //Create the object for the update data VideoPlayerUpdateData videoData = new VideoPlayerUpdateData(avs, null, currentFrame); while (currentFrame <= endPlayFrame && videoPlaying) { actime.Start(); updateVideoData(); // acForm.UpdateGUI(videoData); actime.Stop(); sleepTime = Convert.ToInt32(frameDuration - actime.ElapsedMilliseconds); if (sleepTime < 0) { sleepTime = 0; } Thread.Sleep(sleepTime); currentFrame++; } //Set the flag videoPlaying = false; //Check if stop was pressed if (currentFrame > endPlayFrame) { //The video has reached the end frame updateVideoData(); //acForm.UpdateGUI(videoData); } } catch (Exception ex) { throw new AcException("Error playing video!", ex); } }
public void ReLoad() { try { if (avs != null) { avs.Dispose(); } avs = AvsFile.OpenScriptFile(fileOpened); videoOpened = true; videoData = new VideoPlayerUpdateData(avs, null, currentFrame); updateVideoData(); //acForm.UpdateGUI(videoData); } catch (Exception ex) { throw new AcException("Error reloading video!", ex); } }