private void bw_DoWork(object sender, DoWorkEventArgs e) { /* * UpdatePlayerUriDelegate update = new UpdatePlayerUriDelegate(UpdateNowPlaying); * Dispatcher meDispatcher = mediaElement.Dispatcher; * meDispatcher.BeginInvoke(update, "C:\\1.wmv"); */ int prevDay; string[] timeSplit; int[] timeInInt; int videoCount; bool isNewDay = true; UpdatePlayerUriDelegate updateNowPlaying = new UpdatePlayerUriDelegate(UpdateNowPlaying); Dispatcher mediaElementDispatcher = mediaElement.Dispatcher; UpdateCurrentTimeDelegate updateDisplayTime = new UpdateCurrentTimeDelegate(UpdateDisplayTime); Dispatcher displayTimeDispatcher = displayTime.Dispatcher; do { //get videos ready prevDay = DateTime.Now.Day; string scheduleFileName = "C:\\PeopleBAWX\\" + Utilities.GetMonday(DateTime.Now) + ".xml"; dvf = Utilities.GetTodayScheduleList( scheduleFileName, Utilities.FormatDateYMD(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)); if (dvf == null) { if (isNewDay) { MessageBox.Show("Nothing to broadcast today!"); videoCount = 0; isNewDay = false; } displayTimeDispatcher.BeginInvoke(updateDisplayTime, String.Format("{0:00}", DateTime.Now.Hour) + ":" + String.Format("{0:00}", DateTime.Now.Minute) + ":" + String.Format("{0:00}", DateTime.Now.Second)); Thread.Sleep(1000); //wait for 1 sec } else //do the broadcasting { isNewDay = false; videoCount = dvf.VideoFileList.Count; filesTime = new DateTime[videoCount]; filesLength = new DateTime[videoCount]; filesPath = new string[videoCount]; for (int i = 0; i < videoCount; i++) { VideoFile vf = dvf.VideoFileList.ElementAt(i); timeSplit = vf.Start_Time.Split(':'); timeInInt = new int[3]; for (int j = 0; j < 3; j++) { timeInInt[j] = Int32.Parse(timeSplit[j]); } filesTime[i] = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, timeInInt[0], timeInInt[1], timeInInt[2]); filesPath[i] = vf.Path; timeSplit = vf.Length.Split(':'); timeInInt = new int[3]; for (int j = 0; j < 3; j++) { timeInInt[j] = Int32.Parse(timeSplit[j]); } filesLength[i] = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, timeInInt[0], timeInInt[1], timeInInt[2]); } int videoChecked = 0; while (true) { if (comingUpNext.ToLongTimeString() == DateTime.Now.ToLongTimeString()) { string path = Directory.GetCurrentDirectory() + "..\\Assets\\ComingUp.jpg"; mediaElementDispatcher.BeginInvoke(updateNowPlaying, path); } if (DateTime.Now.Day != prevDay) //next day reached { isNewDay = true; break; } else if (videoChecked == videoCount) { //all the videos for today have been broadcasted //wait for the next day } else { //the schedule for today came late //some shows scheduled early need not be broadcast if (filesTime[videoChecked].Hour < DateTime.Now.Hour || (filesTime[videoChecked].Hour == DateTime.Now.Hour && filesTime[videoChecked].Minute < DateTime.Now.Minute) || (filesTime[videoChecked].Hour == DateTime.Now.Hour && filesTime[videoChecked].Minute == DateTime.Now.Minute && filesTime[videoChecked].Second < DateTime.Now.Second)) { videoChecked++; continue; //skip this iteration } //the time for broadcasting this particular video is reached if (filesTime[videoChecked].ToLongTimeString() == DateTime.Now.ToLongTimeString()) { mediaElementDispatcher.BeginInvoke(updateNowPlaying, "C:\\PeopleBAWX\\" + filesPath[videoChecked]); comingUpNext = DateTime.Now.Add(new TimeSpan( filesLength[videoChecked].Hour, filesLength[videoChecked].Minute, filesLength[videoChecked].Second)); videoChecked++; } } displayTimeDispatcher.BeginInvoke(updateDisplayTime, String.Format("{0:00}", DateTime.Now.Hour) + ":" + String.Format("{0:00}", DateTime.Now.Minute) + ":" + String.Format("{0:00}", DateTime.Now.Second)); Thread.Sleep(1000); //wait for 1 sec } } } while (true); }
private void bw_DoWork(object sender, DoWorkEventArgs e) { /* UpdatePlayerUriDelegate update = new UpdatePlayerUriDelegate(UpdateNowPlaying); Dispatcher meDispatcher = mediaElement.Dispatcher; meDispatcher.BeginInvoke(update, "C:\\1.wmv"); */ int prevDay; string[] timeSplit; int[] timeInInt; int videoCount; bool isNewDay = true; UpdatePlayerUriDelegate updateNowPlaying = new UpdatePlayerUriDelegate(UpdateNowPlaying); Dispatcher mediaElementDispatcher = mediaElement.Dispatcher; UpdateCurrentTimeDelegate updateDisplayTime = new UpdateCurrentTimeDelegate(UpdateDisplayTime); Dispatcher displayTimeDispatcher = displayTime.Dispatcher; do { //get videos ready prevDay = DateTime.Now.Day; string scheduleFileName = "C:\\PeopleBAWX\\" + Utilities.GetMonday(DateTime.Now) + ".xml"; dvf = Utilities.GetTodayScheduleList( scheduleFileName, Utilities.FormatDateYMD(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)); if (dvf == null) { if (isNewDay) { MessageBox.Show("Nothing to broadcast today!"); videoCount = 0; isNewDay = false; } displayTimeDispatcher.BeginInvoke(updateDisplayTime, String.Format("{0:00}", DateTime.Now.Hour) + ":" + String.Format("{0:00}", DateTime.Now.Minute) + ":" + String.Format("{0:00}", DateTime.Now.Second)); Thread.Sleep(1000); //wait for 1 sec } else //do the broadcasting { isNewDay = false; videoCount = dvf.VideoFileList.Count; filesTime = new DateTime[videoCount]; filesLength = new DateTime[videoCount]; filesPath = new string[videoCount]; for (int i = 0; i < videoCount; i++) { VideoFile vf = dvf.VideoFileList.ElementAt(i); timeSplit = vf.Start_Time.Split(':'); timeInInt = new int[3]; for (int j = 0; j < 3; j++) { timeInInt[j] = Int32.Parse(timeSplit[j]); } filesTime[i] = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, timeInInt[0], timeInInt[1], timeInInt[2]); filesPath[i] = vf.Path; timeSplit = vf.Length.Split(':'); timeInInt = new int[3]; for (int j = 0; j < 3; j++) { timeInInt[j] = Int32.Parse(timeSplit[j]); } filesLength[i] = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, timeInInt[0], timeInInt[1], timeInInt[2]); } int videoChecked = 0; while (true) { if (comingUpNext.ToLongTimeString() == DateTime.Now.ToLongTimeString()) { string path = Directory.GetCurrentDirectory() + "..\\Assets\\ComingUp.jpg"; mediaElementDispatcher.BeginInvoke(updateNowPlaying, path); } if (DateTime.Now.Day != prevDay) //next day reached { isNewDay = true; break; } else if (videoChecked == videoCount) { //all the videos for today have been broadcasted //wait for the next day } else { //the schedule for today came late //some shows scheduled early need not be broadcast if (filesTime[videoChecked].Hour < DateTime.Now.Hour || (filesTime[videoChecked].Hour == DateTime.Now.Hour && filesTime[videoChecked].Minute < DateTime.Now.Minute) || (filesTime[videoChecked].Hour == DateTime.Now.Hour && filesTime[videoChecked].Minute == DateTime.Now.Minute && filesTime[videoChecked].Second < DateTime.Now.Second)) { videoChecked++; continue; //skip this iteration } //the time for broadcasting this particular video is reached if (filesTime[videoChecked].ToLongTimeString() == DateTime.Now.ToLongTimeString()) { mediaElementDispatcher.BeginInvoke(updateNowPlaying, "C:\\PeopleBAWX\\" + filesPath[videoChecked]); comingUpNext = DateTime.Now.Add(new TimeSpan( filesLength[videoChecked].Hour, filesLength[videoChecked].Minute, filesLength[videoChecked].Second)); videoChecked++; } } displayTimeDispatcher.BeginInvoke(updateDisplayTime, String.Format("{0:00}", DateTime.Now.Hour) + ":" + String.Format("{0:00}", DateTime.Now.Minute) + ":" + String.Format("{0:00}", DateTime.Now.Second)); Thread.Sleep(1000); //wait for 1 sec } } } while (true); }