/// <summary> /// /// </summary> /// <returns></returns> public async Task GetConfigAndParse() { displayList.Clear(); // clear the list since this function is called when the app resyncs content at mid night audioList.Clear(); // see above StorageFolder displayFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("DigitalSignal\\Display", CreationCollisionOption.OpenIfExists); StorageFolder audioFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("DigitalSignal\\Audio", CreationCollisionOption.OpenIfExists); try { HttpClient configClient = new HttpClient(); string configStr = File.ReadAllText(currentConfigFilePath); XElement xele = XElement.Parse(configStr); foreach (XElement xe in xele.Elements()) { StorageFolder tmp = xe.Name == "Audio" ? audioFolder : displayFolder; List <object> tmpList = xe.Name == "Audio" ? audioList : displayList; foreach (XElement fileElement in xe.Elements()) // audio { if (fileElement.Attribute("type") != null && fileElement.Attribute("type").Value == "webpage") // the display is a webpage, not image, not video, we create and store a new Uri Object. Only url display type has type attribute { DisplayObject DO = new DisplayObject(); DO.uri = new Uri(fileElement.Attribute("path").Value); DO.duration = Convert.ToInt32(fileElement.Attribute("duration").Value); tmpList.Add(DO); } else { DisplayObject DO = new DisplayObject(); string filename = fileElement.Attribute("path").Value.Substring(fileElement.Attribute("path").Value.LastIndexOf('/') + 1); StorageFile file = await tmp.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); Uri fileElementUri; if (Uri.TryCreate(fileElement.Attribute("path").Value, UriKind.Absolute, out fileElementUri) && Uri.CheckSchemeName(fileElementUri.Scheme)) // check if URL or local media { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(fileElementUri); await FileIO.WriteBufferAsync(file, await response.Content.ReadAsBufferAsync()); } else { byte[] bytes = File.ReadAllBytes(filename); await FileIO.WriteBufferAsync(file, WindowsRuntimeBufferExtensions.AsBuffer(bytes)); } if (fileElement.Attribute("duration") != null) // this is an image { DO.duration = Convert.ToInt32(fileElement.Attribute("duration").Value); } DO.file = file; tmpList.Add(DO); } } } } catch (Exception) { // use this to capture any config xml parsing error, we don't expose what they are // but only popup a dialog to user saying something is wrong.. } }
/// <summary> /// /// </summary> /// <returns></returns> public async Task GetConfigAndParse() { displayList.Clear(); // clear the list since this function is called when the app resyncs content at mid night audioList.Clear(); // see above StorageFolder displayFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("DigitalSignal\\Display", CreationCollisionOption.OpenIfExists); StorageFolder audioFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("DigitalSignal\\Audio", CreationCollisionOption.OpenIfExists); try { HttpClient configClient = new HttpClient(); string configStr = File.ReadAllText(currentConfigFilePath); XElement xele = XElement.Parse(configStr); foreach (XElement xe in xele.Elements()) { StorageFolder tmp = xe.Name == "Audio" ? audioFolder : displayFolder; List<object> tmpList = xe.Name == "Audio" ? audioList : displayList; foreach (XElement fileElement in xe.Elements()) // audio { if (fileElement.Attribute("type") != null && fileElement.Attribute("type").Value == "webpage") // the display is a webpage, not image, not video, we create and store a new Uri Object. Only url display type has type attribute { DisplayObject DO = new DisplayObject(); DO.uri = new Uri(fileElement.Attribute("path").Value); DO.duration = Convert.ToInt32(fileElement.Attribute("duration").Value); tmpList.Add(DO); } else { DisplayObject DO = new DisplayObject(); string filename = fileElement.Attribute("path").Value.Substring(fileElement.Attribute("path").Value.LastIndexOf('/') + 1); StorageFile file = await tmp.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); byte[] bytes = File.ReadAllBytes(filename); await FileIO.WriteBufferAsync(file, WindowsRuntimeBufferExtensions.AsBuffer(bytes)); if (fileElement.Attribute("duration") != null) // this is an image DO.duration = Convert.ToInt32(fileElement.Attribute("duration").Value); DO.file = file; tmpList.Add(DO); } } } } catch (Exception) { // use this to capture any config xml parsing error, we don't expose what they are // but only popup a dialog to user saying something is wrong.. } }
/// <summary> /// check if next one is image, continue the audio and display the image for seconds defined by the timer interval /// of next is video, pause the audio, and play back the video /// </summary> async void DisplayNext() { if (displayList.Count == 0) { MessageDialog dialog = new MessageDialog("You've entered an invalid or empty config file, it's been reset to default."); localSettings.Values[configValueName] = defaultConfigFilePath; dialog.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(InvalidConfigDialogCommandInvokeHandler))); dialog.ShowAsync(); // show a dialog with only one button to return to homepage return; } DisplayObject currentDO = (DisplayObject)displayList[currentIndexOfDisplay]; if (currentDO.uri != null) // we're dealing with a WEB Page, show the WebView instance { bool hw = (bool)localSettings.Values["hideWeb"]; if (hw) { currentDO.duration = 0; } videoInstance.Stop(); videoInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; imageInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; webViewInstance.Visibility = Windows.UI.Xaml.Visibility.Visible; webViewInstance.Navigate(currentDO.uri); DisplayImageWEBTimer.Interval = new TimeSpan(0, 0, currentDO.duration); DisplayImageWEBTimer.Start(); PlayAudio(); } else // it must be StorageFile, i.e. image or video { webViewInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; if (imageExtensions.Contains(currentDO.file.FileType.ToLower())) // image, will start or resume audio play back { bool hs = (bool)localSettings.Values["hideSpecials"]; if ((currentDO.file.Name.ToLower().Contains("special")) && (hs)) { currentDO.duration = 0; } videoInstance.Stop(); videoInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; imageInstance.Visibility = Windows.UI.Xaml.Visibility.Visible; imageSource = new BitmapImage(new Uri(currentDO.file.Path)); imageInstance.Width = imageSource.DecodePixelHeight = (int)this.ActualWidth; imageInstance.Source = imageSource; DisplayImageWEBTimer.Interval = new TimeSpan(0, 0, currentDO.duration); DisplayImageWEBTimer.Start(); PlayAudio(); } else // video, we'll pause audio playback { audioInstance.Pause(); videoInstance.Source = new Uri(currentDO.file.Path); audioInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; imageInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; videoInstance.Visibility = Windows.UI.Xaml.Visibility.Visible; videoInstance.Play(); } } currentIndexOfDisplay = (++currentIndexOfDisplay) % displayList.Count; // make the index in a loop }