public async Task <int> SaveEpisodeItemAsync(RssEpisode item, bool doPublish = false) { if (episodes == null) { episodes = new List <RssEpisode>(); } var result = 0; if (item.Id != null && item.Id != 0) { var oldItem = episodes.Where((RssEpisode arg) => arg.Id == item.Id).FirstOrDefault(); episodes.Remove(oldItem); episodes.Add(item); result = await Database.UpdateAsync(item); } else { var maxId = await GetMaxRssEpisodeId(); item.Id = maxId + 1; episodes.Add(item); result = await Database.InsertAsync(item); } if (result > 0 && doPublish) { var updateEpisodeMessage = new UpdateEpisodeMessage { RssEpisode = item }; MessagingCenter.Send(updateEpisodeMessage, "UpdateEpisodeMessage"); //goes to listening ViewModels that can download } return(result); }
public async Task <RssEpisode> PauseEpisodeAsync(RssEpisode episode) { RssEpisode returnEpisode = null; try { if (PodcastPlayer.Instance.IsPlaying) { //player pause PodcastPlayer.Instance.PlayPause(); //get episode to update episode = PodcastPlayer.Instance.Episode; //update icon on item - updates screen SetEpisodeToPause(ref episode); //broadcast to other viewmodels var pauseMessage = new UpdateEpisodeMessage { RssEpisode = episode }; MessagingCenter.Send(pauseMessage, "StopEpisodePlaying"); //update current position episode.CurrentPosition = PodcastPlayer.Instance.CurrentPosition; //save episode - updates db var result = await DataStore.SaveEpisodeItemAsync(episode); if (result == 0) { Debug.WriteLine("RssEpisodeListViewModel.ExecutePauseCommandAsync Could Not update RssEpisode with start playing"); } returnEpisode = episode; } else { Debug.WriteLine("RssEpisodeListViewModel.ExecutePauseCommandAsync player is not playing "); //get episode to update var playerEpisode = PodcastPlayer.Instance.Episode; if (playerEpisode == null) { playerEpisode = episode; } //update icon on item - updates screen SetEpisodeToPause(ref playerEpisode); //save episode - updates db var result = await DataStore.SaveEpisodeItemAsync(playerEpisode); if (result == 0) { Debug.WriteLine("RssEpisodeListViewModel.ExecutePauseCommandAsync Could Not update RssEpisode with start playing"); } returnEpisode = playerEpisode; } } catch (Exception ex) { //could not delete item Debug.WriteLine("RssEpisodeListViewModel.ExecutePauseCommandAsync Could not Pause Podcast File " + ex.Message); } return(returnEpisode); }
void OnPlaybackEnded(object sender, EventArgs e) { Stop(); PlaybackEnded?.Invoke(sender, e); var startMessage = new UpdateEpisodeMessage { RssEpisode = Episode }; MessagingCenter.Send(startMessage, "PlaybackEnded"); }
public async Task <RssEpisode> PlayEpisodeAsync(RssEpisode episode) { try { if (episode != null && episode.Id != null) { if (PodcastPlayer.Instance.IsPlaying) { //save the current play position of the other episode then start playing this episode //pause other episode var playerEpisode = PodcastPlayer.Instance.Episode; //if player is playing this should never be null await PauseEpisodeAsync(playerEpisode); //pause the other episode //play this episode await PlayEpisodeAsync(episode); } else { //update icon on item - updates screen SetEpisodeToPlaying(ref episode); //broadcast to other viewmodels var startMessage = new UpdateEpisodeMessage { RssEpisode = episode }; MessagingCenter.Send(startMessage, "StartEpisodePlaying"); //save episode - updates db var result = await DataStore.SaveEpisodeItemAsync(episode); if (result == 0) { Debug.WriteLine("RssEpisodeListViewModel.ExecutePlayCommandAsync Could Not update RssEpisode with start playing"); } //player load episode PodcastPlayer.Instance.Episode = episode; //update current position if (episode.CurrentPosition > 0) { PodcastPlayer.Instance.CurrentPosition = episode.CurrentPosition; } //player play PodcastPlayer.Instance.PlayPause(); } } else { Debug.WriteLine("RssEpisodeListViewModel.ExecutePlayCommandAsync episode or episode id was null "); } } catch (Exception ex) { //could not delete item Debug.WriteLine("RssEpisodeListViewModel.ExecutePlayCommandAsync Could not Play Podcast File " + ex.Message); } return(episode); }