private void UpdateCurrentNextStreamItems() { ExpoScheduledStreamItem newCurrentStreamItem = ExpoScheduleManager.Instance.GetCurrentScheduledStreamItem(StreamRoomName, currentTime); ExpoScheduledStreamItem newNextStreamItem = ExpoScheduleManager.Instance.GetNextScheduledStreamItem(StreamRoomName, currentTime); if (newCurrentStreamItem != currentStreamItem || newNextStreamItem != nextStreamItem) { currentStreamItem = newCurrentStreamItem; nextStreamItem = newNextStreamItem; _isDirtyStreams = true; } }
private IEnumerator ScheduledStreamCoroutine() { scheduledStreamIsActive = true; activeStreamItem = null; while (scheduledStreamIsActive) { while (!internetTimeReady) { yield return(new WaitForSecondsRealtime(0.5f)); } currentTime = internetTimeCached.AddSeconds(Time.realtimeSinceStartup - internetTimeCachedMoment); currentTimeString = currentTime.ToString(); UpdateCurrentNextStreamItems(); if (_isDirtyStreams) { activeStreamItem = null; StreamState = ExpoScheduledStreamState.Start; } if (StreamState == ExpoScheduledStreamState.Start) { if (currentStreamItem != null) { activeStreamItem = currentStreamItem; OpenStreamFile(); } else { OnFinished(); } } else if (StreamState == ExpoScheduledStreamState.Ready) { if (currentTime >= activeStreamItem.StartTime) { float timeStampSec = (float)currentTime.Subtract(activeStreamItem.StartTime).TotalSeconds; if (timeStampSec < activeStreamDurationSec) { PlayStreamFile(timeStampSec); } else { OnFinished(); } } } else if (StreamState == ExpoScheduledStreamState.Playing) { } else if (StreamState == ExpoScheduledStreamState.Waiting) { // next stream always not null if (activeStreamItem != null) { if (activeStreamItem != nextStreamItem) { activeStreamItem = nextStreamItem; OpenStreamFile(); } else { StreamState = ExpoScheduledStreamState.Ready; } } else { activeStreamItem = nextStreamItem; OpenStreamFile(); } } else if (StreamState == ExpoScheduledStreamState.Over) { activeStreamItem = null; CloseStreamFile(); } else if (StreamState == ExpoScheduledStreamState.WaitAcyncOperation) { } _isDirtyStreams = false; timeBeforeNextStreamSec = 0; if (nextStreamItem != null) { timeBeforeNextStreamSec = Mathf.RoundToInt((float)nextStreamItem.StartTime.Subtract(currentTime).TotalSeconds); } UpdateText(); yield return(new WaitForSecondsRealtime(scheduledStreamUpdatePeriod)); } yield return(null); }
private void ParseSchedule() { LanguageSourceData sourceData = I2.Loc.LocalizationManager.Sources[0]; categoriesList = new List <string>(); categoriesList = sourceData.GetCategories(); streamCategoriesList = categoriesList.FindAll(x => x.StartsWith(categoryMainName)); foreach (string streamCategory in streamCategoriesList) { termsList.AddRange(sourceData.GetTermsList(streamCategory)); } termsList.Sort(); string key; string category; foreach (string term in termsList) { key = ""; category = ""; LanguageSourceData.DeserializeFullTerm(term, out key, out category); string[] subCategories = category.Split('/'); int streamId = 0; foreach (string item in subCategories) { if (item.StartsWith(categoryStreamName)) { int.TryParse(item.Substring(categoryStreamName.Length), out streamId); } } ExpoScheduledStreamItem scheduledItem = scheduledItems.Find(x => x.category == category); bool isNew = false; if (scheduledItem == null) { isNew = true; scheduledItem = new ExpoScheduledStreamItem(); scheduledItem.StreamId = streamId; scheduledItem.category = category; } if (key == keyRoom) { // Room name is equal to Timetable Tab names scheduledItem.Room = sourceData.GetTranslation(term); } else if (key == keyDayId) { int dayIdParse = 0; if (!int.TryParse(sourceData.GetTranslation(term), out dayIdParse)) { dayIdParse = 0; } scheduledItem.DayId = dayIdParse; } else if (key == keyStartTime) { string dateString = sourceData.GetTranslation(term); dateString = dateString.Replace("GMT", "").Replace(" (PDT)", "").Replace(" (PST)", "").Replace(" (PT)", ""); dateString = dateString.Insert(dateString.Length - 2, ":"); scheduledItem.StartTime = System.DateTime.ParseExact(dateString, dateFormat, System.Globalization.CultureInfo.InvariantCulture); scheduledItem.StartTimeString = scheduledItem.StartTime.ToString(); scheduledItem.Date = scheduledItem.StartTime.ToLocalTime().Date; scheduledItem.DateString = scheduledItem.Date.ToShortDateString(); } else if (key == keyEndTime) { string dateString = sourceData.GetTranslation(term); dateString = dateString.Replace("GMT", "").Replace(" (PDT)", "").Replace(" (PST)", "").Replace(" (PT)", ""); dateString = dateString.Insert(dateString.Length - 2, ":"); scheduledItem.EndTime = System.DateTime.ParseExact(dateString, dateFormat, System.Globalization.CultureInfo.InvariantCulture); scheduledItem.EndTimeString = scheduledItem.EndTime.ToString(); } else if (key == keyTitle) { scheduledItem.Title = sourceData.GetTranslation(term); } else if (key == keyDescription) { scheduledItem.Description = sourceData.GetTranslation(term); } else if (key == keySpeakersName) { scheduledItem.SpeakersName = sourceData.GetTranslation(term); } else if (key == keySpeakersPosition) { scheduledItem.SpeakersPosition = sourceData.GetTranslation(term); } else if (key == keySpeakersPhoto) { scheduledItem.SpeakersPhoto = sourceData.GetTranslation(term); } else if (key == keyFormat) { scheduledItem.Format = sourceData.GetTranslation(term); } else if (key == keyURL) { scheduledItem.URL = sourceData.GetTranslation(term); } if (isNew) { scheduledItems.Add(scheduledItem); } } scheduledItems = scheduledItems.OrderBy(x => x.StartTime).ToList(); }