public static void loadByVocabulary(Vocabulary _item) { if (_item.Id == 0) { Helper.ShowToast("Chưa có dữ liệu từ điển. Vui lòng import."); return; } ToastContent content; if (String.IsNullOrEmpty(_item.PlayURL)) { content = getToastContentWithoutPlay(_item); } else { Mp3.preloadMp3FileSingle(_item); content = getToastContent(_item); } var _toastItem = new ToastNotification(content.GetXml()) { Tag = "Vocabulary", Group = "Reminder", }; _toastItem.Dismissed += ToastDismissed; _toastItem.Failed += ToastFailed; _toastItem.Priority = ToastNotificationPriority.High; ToastNotificationManager.CreateToastNotifier().Show(_toastItem); }
public void OnMediaEnded(MediaPlayer mediaPlayer, object args) { while (listPlayMp3.Count() > 0) { var currentUrl = listPlayMp3.Dequeue(); Mp3.play(currentUrl); } }
private async Task ProcessBackgroundPreLoadMp3() { try { var ListVocabulary = DataAccess.GetListVocabularyToPreloadMp3(); ParallelOptions parallelOptions = new ParallelOptions(); parallelOptions.MaxDegreeOfParallelism = (int)Environment.ProcessorCount / 2; // TODO await Task.Run(() => Parallel.ForEach(ListVocabulary, parallelOptions, async _item => { await Mp3.preloadMp3Multiple(_item); })); Helper.ShowToast("Crawling: Process Background Download MP3 Files Finished."); } catch (Exception ex) { Helper.ShowToast("Crawling: Process Background Get Play URL Fail: " + ex.Message); } }
private void processCustomAction(string main_action, QueryString args) { try { switch (main_action) { case "reload": WordId = int.Parse(args["WordId"]); var _item = DataAccess.GetVocabularyById(WordId); VocabularyToast.loadByVocabulary(_item); _item = null; break; case "play": WordId = int.Parse(args["WordId"]); int playId = int.Parse(args["PlayId"]); if (WordId > 0) { string _mp3Url; if (VocabularyToast.reloadLastToast()) { _mp3Url = args["PlayUrl"]; } else { _item = DataAccess.GetVocabularyById(WordId); VocabularyToast.loadByVocabulary(_item); if (playId == 2) { _mp3Url = _item.PlayURL2; } else { _mp3Url = _item.PlayURL; } } if (!String.IsNullOrEmpty(_mp3Url)) { if (mediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Playing) { listPlayMp3.Enqueue(_mp3Url); } else { checkMediaPlayer(); Mp3.play(_mp3Url); } } } break; case "next": WordId = int.Parse(args["WordId"]); if (WordId > 0) { WordId++; } else { WordId = DataAccess.GetFirstWordId(); } var _item2 = DataAccess.GetVocabularyById(WordId); VocabularyToast.loadByVocabulary(_item2); _item2 = null; break; case "view": string SearchUrl = args["url"]; // The URI to launch var uriBing = new Uri(SearchUrl); // Launch the URI var success = Windows.System.Launcher.LaunchUriAsync(uriBing); break; } } catch (Exception ex) { Helper.ShowToast("Action Background Error: " + ex.Message); } }