/// <summary> /// Goes into a season folder, gets all files in the folder path, picks one and plays it if it is a video file /// </summary> /// <param name="folderPath">Path to pick file from</param> /// <param name="rnd">Random number generator</param> /// <returns>True if the video is started</returns> private bool PickAndPlayVideoFile(string folderPath) { // Stop the timer if it's running if (timer.Enabled) { timer.Stop(); } // Get all files in the folder and pick one var files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories).Where(f => IsVideoFile(f)).ToArray(); var file = files.Count() > 0 ? files[rnd.Next(files.Count())] : null; // If it's a video file, play it and break the loop try { // Open the file in the media player control, set and start timer new Thread(() => { Thread.CurrentThread.IsBackground = true; ShowPlayer.currentMedia = ShowPlayer.newMedia(file); }).Start(); PlayLabel_Click(null, null); timer.Interval = (int)(ShowPlayer.newMedia(file).duration * 1000); timer.Start(); return(true); } catch (Exception) { } return(false); }
public PlayerWindow(string filepath) { InitializeComponent(); Show(); ShowPlayer.openPlayer(filepath); ShowPlayer.settings.autoStart = true; var show = ShowPlayer.newMedia(filepath); timer.Tick += Timer_Tick; timer.Interval = (int)(show.duration * 1000) + 1; ShowPlayer.currentMedia = show; while (ShowPlayer.openState != WMPLib.WMPOpenState.wmposMediaOpen || ShowPlayer.playState != WMPLib.WMPPlayState.wmppsPlaying) { } timer.Start(); ShowPlayer.fullScreen = true; }