public static showErrorToast ( string message ) : void | ||
message | string | |
리턴 | void |
void wc_DownloadOPMLCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { App.showErrorToast("Cannot fetch OPML from that location."); SubscriptionManagerArgs args = new SubscriptionManagerArgs(); args.message = "Cannot fetch OPML from that location."; OnPodcastChannelAddFinishedWithError(this, args); return; } String opml = e.Result as String; List <Uri> subscriptions = PodcastFactory.podcastUrlFromOPMLImport(opml); if (subscriptions == null || subscriptions.Count < 1) { App.showNotificationToast("No subscriptions to import."); SubscriptionManagerArgs args = new SubscriptionManagerArgs(); args.message = "No podcasts to import."; OnPodcastChannelAddFinishedWithError(this, args); return; } foreach (Uri subscription in subscriptions) { addSubscriptionFromURL(subscription.ToString(), true); } }
private void updatePlayerPosition() { TimeSpan position = TimeSpan.Zero; settingSliderFromPlay = true; try { if ((BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing || BackgroundAudioPlayer.Instance.PlayerState != PlayState.Paused) && (BackgroundAudioPlayer.Instance.Track == null || BackgroundAudioPlayer.Instance.Position == null)) { settingSliderFromPlay = false; return; } position = BackgroundAudioPlayer.Instance.Position; CurrentPositionText.Text = position.ToString("hh\\:mm\\:ss"); TotalDurationText.Text = BackgroundAudioPlayer.Instance.Track.Duration.ToString("hh\\:mm\\:ss"); PositionSlider.Value = getEpisodePlayPosition(); } catch (InvalidOperationException ioe) { Debug.WriteLine("Error when updating player: " + ioe.Message); } catch (SystemException syse) { Debug.WriteLine("Error when updating player: " + syse.Message); App.showErrorToast("WP8 cannot play from this location."); PlaybackStopped(); } settingSliderFromPlay = false; }
private void playButtonClicked(object sender, System.Windows.Input.GestureEventArgs e) { if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing) { BackgroundAudioPlayer.Instance.Pause(); setupUIForEpisodePaused(); } else if (BackgroundAudioPlayer.Instance.Track != null) { BackgroundAudioPlayer.Instance.Play(); setupUIForEpisodePlaying(); } else { Debug.WriteLine("No track currently set. Trying to setup currently playing episode as track..."); PodcastEpisodeModel ep = PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode; if (ep != null) { PodcastPlaybackManager.getInstance().play(ep); } else { Debug.WriteLine("Error: No currently playing track either! Giving up..."); App.showErrorToast("Something went wrong. Cannot play the track."); showNoPlayerLayout(); } } }
private void startPlayback(PodcastEpisodeModel episode, TimeSpan position, bool streamEpisode = false) { AudioTrack playTrack = null; if (streamEpisode) { playTrack = getAudioStreamForEpisode(episode); } else { playTrack = getAudioTrackForEpisode(episode); } if (playTrack == null) { App.showErrorToast("Cannot play the episode."); return; } try { // BackgroundAudioPlayer.Instance.PlayStateChanged -= new EventHandler(PlayStateChanged); // BackgroundAudioPlayer.Instance.PlayStateChanged += new EventHandler(PlayStateChanged); BackgroundAudioPlayer.Instance.Track = playTrack; BackgroundAudioPlayer.Instance.Volume = 1.0; PlayButtonImage.Source = m_pauseButtonBitmap; // This should really be on the other side of BackgroundAudioPlayer.Instance.Position // then for some reason it's not honored. BackgroundAudioPlayer.Instance.Play(); if (position.Ticks > 0) { BackgroundAudioPlayer.Instance.Position = new TimeSpan(position.Ticks); } } catch (Exception) { Debug.WriteLine("I've read from Microsoft that something stupid can happen if you try to start " + "playing and there's a YouTube video playing. This this try-catch is really just " + "to guard against Microsoft's bug."); } }
public void addSubscriptionFromOPMLFile(string opmlFileUrl) { Uri uri = null; bool valid = Uri.TryCreate(opmlFileUrl, System.UriKind.Absolute, out uri); if (!valid) { App.showErrorToast("Cannot fetch OPML from that location."); return; } MessageBox.Show("A blank screen may appear for a longer period of time. Please wait until the import has completed and do not exit the app."); WebClient wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadOPMLCompleted); wc.DownloadStringAsync(uri); OnPodcastChannelAddStarted(this, null); }
public void playEpisode(PodcastEpisodeModel episodeModel) { Debug.WriteLine("Starting playback for episode: " + episodeModel.EpisodeName); if (PodcastPlaybackManager.isAudioPodcast(episodeModel)) { try { audioPlayback(episodeModel); } catch (FileNotFoundException e) { Console.WriteLine("Error: File not found. " + e.Message); App.showErrorToast("Cannot find episode."); } } else { videoPlayback(episodeModel); } }
internal void playEpisode(PodcastEpisodeModel episodeModel) { Debug.WriteLine("Starting playback for episode: " + episodeModel.EpisodeName); if (PodcastPlaybackManager.isAudioPodcast(episodeModel)) { try { audioPlayback(episodeModel); setupUIForEpisodePlaying(); } catch (FileNotFoundException e) { Console.WriteLine("Error: File not found. " + e.Message); App.showErrorToast("Cannot find episode."); showNoPlayerLayout(); } } else { PlaybackStopped(); videoPlayback(episodeModel); } }
private void playButtonClicked(object sender, EventArgs e) { if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing) { // Paused BackgroundAudioPlayer.Instance.Pause(); // PodcastPlayer.setupUIForEpisodePaused(); // PlayButtonImage.Source = m_playButtonBitmap; (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IconUri = new Uri("/Images/Light/play.png", UriKind.Relative); (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).Text = "Play"; } else if (BackgroundAudioPlayer.Instance.Track != null) { // Playing BackgroundAudioPlayer.Instance.Play(); // PodcastPlayer.setupUIForEpisodePlaying(); // PlayButtonImage.Source = m_pauseButtonBitmap; (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IconUri = new Uri("/Images/Light/pause.png", UriKind.Relative); (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).Text = "Pause"; } else { Debug.WriteLine("No track currently set. Trying to setup currently playing episode as track..."); PodcastEpisodeModel ep = PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode; if (ep != null) { PodcastPlaybackManager.getInstance().play(ep); } else { Debug.WriteLine("Error: No currently playing track either! Giving up..."); App.showErrorToast("Something went wrong. Cannot play the track."); // PodcastPlayer.showNoPlayerLayout(); } } }
private void completePodcastDownload(BackgroundTransferRequest transferRequest) { // If the status code of a completed transfer is 200 or 206, the // transfer was successful if (transferRequest.TransferError == null && (transferRequest.StatusCode == 200 || transferRequest.StatusCode == 206)) { Debug.WriteLine("Transfer request completed succesfully."); updateEpisodeWhenDownloaded(m_currentEpisodeDownload); // Add downloaded episode to play queue, if set. using (var db = new PodcastSqlModel()) { if (db.settings().IsAddDownloadsToPlayQueue) { PodcastPlaybackManager.getInstance().addSilentlyToPlayqueue(m_currentEpisodeDownload); } } } else { Debug.WriteLine("Transfer request completed with error code: " + transferRequest.StatusCode + ", " + transferRequest.TransferError); switch (transferRequest.StatusCode) { case 0: Debug.WriteLine("Request canceled."); break; // If error code is 200 but we still got an error, this means the max. transfer size exceeded. // This is because the podcast feed announced a different download size than what the file actually is. // If user wants, we can try again with larger file download size policy. case 200: Debug.WriteLine("Maxiumum download size exceeded. Shall we try again?"); if (MessageBox.Show("Podcast feed announced wrong file size. Do you want to download again with larger file download settings?", "Podcast download failed", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { if (MessageBox.Show("Please connect your phone to an external power source and to a WiFi network.", "Attention", MessageBoxButton.OK) == MessageBoxResult.OK) { Debug.WriteLine("Download the same episode again, with preferences None."); // We download the same file again, but this time we force the TransferPrefernces to be None. startNextEpisodeDownload(TransferPreferences.None); return; } } break; case 301: App.showErrorToast("WP8 cannot download from this location."); break; default: App.showErrorToast("Could not download the episode\nfrom the server."); break; } if (m_currentEpisodeDownload != null) { m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle; m_currentEpisodeDownload.deleteDownloadedEpisode(); } } saveEpisodeInfoToDB(m_currentEpisodeDownload); cleanupEpisodeDownload(transferRequest); // And start a next round of downloading. startNextEpisodeDownload(); }
private void startNextEpisodeDownload(TransferPreferences useTransferPreferences = TransferPreferences.AllowCellularAndBattery) { if (BackgroundTransferService.Requests.Count() > 0) { // For some reason there are still old requests in the background transfer service. // Let's clean everything and start over. foreach (BackgroundTransferRequest t in BackgroundTransferService.Requests.AsEnumerable()) { BackgroundTransferService.Remove(t); } } if (m_episodeDownloadQueue.Count > 0) { m_currentEpisodeDownload = m_episodeDownloadQueue.Peek(); Uri downloadUri; try { downloadUri = new Uri(m_currentEpisodeDownload.EpisodeDownloadUri, UriKind.Absolute); } catch (Exception e) { App.showErrorToast("Cannot download the episode."); Debug.WriteLine("Cannot download the episode. URI exception: " + e.Message); m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle; m_episodeDownloadQueue.Dequeue(); saveEpisodeInfoToDB(m_currentEpisodeDownload); startNextEpisodeDownload(); return; } m_currentEpisodeDownload.EpisodeFile = generateLocalEpisodeFileName(m_currentEpisodeDownload); if (string.IsNullOrEmpty(m_currentEpisodeDownload.EpisodeFile)) { App.showErrorToast("Cannot download the episode."); Debug.WriteLine("Cannot download the episode. Episode file name is null or empty."); m_currentEpisodeDownload.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle; m_episodeDownloadQueue.Dequeue(); saveEpisodeInfoToDB(m_currentEpisodeDownload); startNextEpisodeDownload(); return; } // Create a new background transfer request for the podcast episode download. m_currentBackgroundTransfer = new BackgroundTransferRequest(downloadUri, new Uri(m_currentEpisodeDownload.EpisodeFile, UriKind.Relative)); if (useTransferPreferences == TransferPreferences.None) { m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.None; } else if (canAllowCellularDownload(m_currentEpisodeDownload)) { bool settingsAllowCellular = false; using (var db = new PodcastSqlModel()) { settingsAllowCellular = db.settings().IsUseCellularData; } Debug.WriteLine("Settings: Allow cellular download: " + settingsAllowCellular); if (settingsAllowCellular && canDownloadOverCellular()) { m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.AllowCellularAndBattery; } else { m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.AllowBattery; } } else { m_currentBackgroundTransfer.TransferPreferences = TransferPreferences.None; } Debug.WriteLine("m_currentBackgroundTransfer.TransferPreferences = " + m_currentBackgroundTransfer.TransferPreferences.ToString()); m_currentBackgroundTransfer.TransferStatusChanged += new EventHandler <BackgroundTransferEventArgs>(backgroundTransferStatusChanged); // Store request to the episode. m_currentEpisodeDownload.DownloadRequest = m_currentBackgroundTransfer; m_applicationSettings.Remove(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID); m_applicationSettings.Add(App.LSKEY_PODCAST_EPISODE_DOWNLOADING_ID, m_currentEpisodeDownload.EpisodeId); m_applicationSettings.Save(); try { BackgroundTransferService.Add(m_currentBackgroundTransfer); } catch (InvalidOperationException) { foreach (BackgroundTransferRequest r in BackgroundTransferService.Requests) { BackgroundTransferService.Remove(r); } BackgroundTransferService.Add(m_currentBackgroundTransfer); } } }