void PlayStateChanged(object sender, EventArgs e) { if (BackgroundAudioPlayer.Instance.Error != null) { Debug.WriteLine("PlayStateChanged: Podcast player is no longer available."); return; } switch (BackgroundAudioPlayer.Instance.PlayerState) { case PlayState.Playing: // Player is playing Debug.WriteLine("Podcast player is playing..."); break; case PlayState.Paused: // Player is on pause Debug.WriteLine("Podcast player is paused."); break; case PlayState.Shutdown: case PlayState.Unknown: case PlayState.Stopped: // Player stopped Debug.WriteLine("Podcast player stopped."); m_currentPlayerEpisode = null; break; case PlayState.TrackEnded: break; } }
public void playPlaylistItem(int tappedPlaylistItemId) { int episodeId = -1; using (var db = new PlaylistDBContext()) { if (db.Playlist.Count() < 1) { return; } episodeId = (int)db.Playlist.Where(item => item.ItemId == tappedPlaylistItemId).Select(item => item.EpisodeId).First(); } PodcastEpisodeModel episode = null; using (var db = new PodcastSqlModel()) { episode = db.Episodes.First(ep => ep.EpisodeId == episodeId); } if (episode != null) { play(episode, true); } else { Debug.WriteLine("Warning: Could not play episode: " + episodeId); } }
private void Episode_Tap(object sender, System.Windows.Input.GestureEventArgs e) { PodcastEpisodeModel podcastEpisode = this.DataContext as PodcastEpisodeModel; PhoneApplicationFrame applicationFrame = Application.Current.RootVisual as PhoneApplicationFrame; applicationFrame.Navigate(new Uri(string.Format("/Views/PodcastEpisodeDescriptionView.xaml?episodeId={0}", (this.DataContext as PodcastEpisodeModel).EpisodeId), UriKind.Relative)); }
private AudioTrack getAudioTrackForEpisode(PodcastEpisodeModel currentEpisode) { if (currentEpisode == null || String.IsNullOrEmpty(currentEpisode.EpisodeFile)) { return(null); } Uri episodeLocation; try { episodeLocation = new Uri(currentEpisode.EpisodeFile, UriKind.Relative); } catch (Exception) { return(null); } using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.First(s => s.PodcastId == currentEpisode.PodcastId); return(new AudioTrack(episodeLocation, currentEpisode.EpisodeName, sub.PodcastName, "", new Uri(sub.PodcastLogoLocalLocation, UriKind.Relative))); } }
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(); } } }
public void startDefaultBehaviorPlayback() { using (PodcastSqlModel db = new PodcastSqlModel()) { try { PodcastEpisodeModel latestPlayed = db.Episodes.Where(ep => (ep.LastPlayed.HasValue == true && ep.LastPlayed.Value.Year > 2013)).OrderByDescending(ep => ep.LastPlayed).FirstOrDefault(); if (latestPlayed != null) { App.showNotificationToast("Playing recently played episode."); play(latestPlayed); return; } } catch (InvalidOperationException) { Debug.WriteLine("Could not find a suitable latest episode played."); } // Did not find a suitable episode that was previously played, so we have to start a "new" playback. // This playback is the latest published episode. PodcastEpisodeModel newestEpisode = db.Episodes.OrderByDescending(ep => ep.EpisodePublished).FirstOrDefault(); if (newestEpisode != null) { App.showNotificationToast("Playing newest episode."); play(newestEpisode); } else { Debug.WriteLine("Uups, cannot find a newest episode to play."); } } }
private AudioTrack getAudioStreamForEpisode(PodcastEpisodeModel episode) { if (episode == null || String.IsNullOrEmpty(episode.EpisodeDownloadUri)) { return(null); } Uri episodeLocation; try { episodeLocation = new Uri(episode.EpisodeDownloadUri, UriKind.Absolute); } catch (Exception) { return(null); } using (var db = new PodcastSqlModel()) { PodcastSubscriptionModel sub = db.Subscriptions.First(s => s.PodcastId == episode.PodcastId); return(new AudioTrack(episodeLocation, episode.EpisodeName, sub.PodcastName, "", new Uri(sub.PodcastLogoLocalLocation, UriKind.Relative))); } }
public PodcastEpisodeModel updateCurrentlyPlayingEpisode() { PlaylistItem plItem = null; using (var playlistDb = new PlaylistDBContext()) { if (playlistDb.Playlist.Count() == 0) { return(null); } plItem = playlistDb.Playlist.Where(item => item.IsCurrent).FirstOrDefault(); } if (plItem != null) { using (var db = new PodcastSqlModel()) { PodcastEpisodeModel currentEpisode = db.Episodes.Where(ep => ep.EpisodeId == plItem.EpisodeId).FirstOrDefault(); CurrentlyPlayingEpisode = currentEpisode; return(currentEpisode); } } return(null); }
public static bool isAudioPodcast(PodcastEpisodeModel episode) { bool audio = false; // We have to treat empty as an audio, because that was what the previous // version had for mime type and we don't want to break the functionality. if (String.IsNullOrEmpty(episode.EpisodeFileMimeType)) { return(true); } switch (episode.EpisodeFileMimeType) { case "audio/mpeg": case "audio/mp3": case "audio/x-mp3": case "audio/mpeg3": case "audio/x-mpeg3": case "audio/mpg": case "audio/x-mpg": case "audio/x-mpegaudio": case "audio/x-m4a": case "audio/mpegaudio": case "audio/m4a": case "audio/x-mpeg": case "media/mpeg": case "x-audio/mp3": case "audio/x-mpegurl": audio = true; break; } return(audio); }
public void removeFromPlayqueue(int itemId) { using (var db = new PlaylistDBContext()) { PlaylistItem itemToRemove = db.Playlist.FirstOrDefault(item => item.ItemId == itemId); if (itemToRemove != null) { PodcastEpisodeModel episode = null; using (var episodeDb = new PodcastSqlModel()) { episode = episodeDb.episodeForPlaylistItem(itemToRemove); if (episode != null) { if (episode.isListened()) { episode.markAsListened(episodeDb.settings().IsAutoDelete); } } else { Debug.WriteLine("Warning: Could not get episode for item id: " + itemToRemove.ItemId); } } db.Playlist.DeleteOnSubmit(itemToRemove); db.SubmitChanges(); App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>(); } } }
public void newDownloadedEpisode(PodcastEpisodeModel e) { if (NewPlayableEpisode != null) { NewPlayableEpisode(e); } }
private void startNewPlayback(PodcastEpisodeModel episodeModel, bool streaming) { m_currentPlayerEpisode = episodeModel; setupPlayerUIContent(episodeModel); updatePrimary(episodeModel); if (episodeModel.SavedPlayPos > 0) { bool alwaysContinuePlayback = false; using (var db = new PodcastSqlModel()) { alwaysContinuePlayback = db.settings().IsAutomaticContinuedPlayback; } if (alwaysContinuePlayback) { startPlayback(episodeModel, new TimeSpan(episodeModel.SavedPlayPos), streaming); } else { askForContinueEpisodePlaying(episodeModel, streaming); } } else { startPlayback(episodeModel, TimeSpan.Zero, streaming); } }
public void removedPlayableEpisode(PodcastEpisodeModel e) { if (RemovedPlayableEpisode != null) { RemovedPlayableEpisode(e); } }
public static void notifyUserOfDownloadRestrictions(PodcastEpisodeModel episode) { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; // Notify about >100 MB downloads if (!settings.Contains(App.LSKEY_NOTIFY_DOWNLOADING_WITH_WIFI) && episode.EpisodeDownloadSize > App.MAX_SIZE_FOR_WIFI_DOWNLOAD_NO_POWER) { if (MessageBox.Show("You are about to download a file over 100 MB in size. " + "Please note that Windows Phone allows downloading this kind of files only if " + "you are connected to a WiFi network and connected to an external power source.", "Attention", MessageBoxButton.OK) == MessageBoxResult.OK) { settings.Add(App.LSKEY_NOTIFY_DOWNLOADING_WITH_WIFI, true); return; } } // Notify about >20 MB downloads if (!settings.Contains(App.LSKEY_NOTIFY_DOWNLOADING_WITH_CELLULAR) && episode.EpisodeDownloadSize > App.MAX_SIZE_FOR_CELLULAR_DOWNLOAD) { if (MessageBox.Show("You are about to download a file over 20 MB in size. Please " + "note that Windows Phone allows downloading this kind of files only if you are " + "connected to a WiFi network.", "Attention", MessageBoxButton.OK) == MessageBoxResult.OK) { settings.Add(App.LSKEY_NOTIFY_DOWNLOADING_WITH_CELLULAR, true); return; } } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs naviArgs) { this.DownloadButton.Visibility = System.Windows.Visibility.Collapsed; try { int podcastEpisodeId = int.Parse(NavigationContext.QueryString["episodeId"]); using (var db = new PodcastSqlModel()) { m_podcastEpisode = db.episodeForEpisodeId(podcastEpisodeId); if (m_podcastEpisode != null) { this.DataContext = m_podcastEpisode; if (m_podcastEpisode.isPlayable() && String.IsNullOrEmpty(m_podcastEpisode.EpisodeFile)) { this.DownloadButton.Visibility = System.Windows.Visibility.Visible; } } else { Debug.WriteLine("Episode model is null. Cannot show description."); } } } catch (Exception e) { Debug.WriteLine("Cannot get episode id. Error: " + e.Message); } }
public void initializePlayerUI() { PodcastEpisodeModel currentlyPlayingEpisode = PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode; restoreEpisodeToPlayerUI(currentlyPlayingEpisode); m_currentPlayerEpisode = currentlyPlayingEpisode; updatePlayerPosition(); }
internal PodcastEpisodeModel episodesForTitle(String episodeTitle) { PodcastEpisodeModel episode = (from e in Episodes where e.EpisodeName == episodeTitle select e).FirstOrDefault(); return(episode); }
private void DownloadButton_Click(object sender, RoutedEventArgs e) { m_episodeModel = this.DataContext as PodcastEpisodeModel; PodcastEpisodesDownloadManager downloadManager = PodcastEpisodesDownloadManager.getInstance(); PodcastEpisodesDownloadManager.notifyUserOfDownloadRestrictions(m_episodeModel); downloadManager.addEpisodeToDownloadQueue(m_episodeModel); }
private void videoPlayback(PodcastEpisodeModel episodeModel) { MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher(); mediaPlayerLauncher.Media = new Uri(episodeModel.EpisodeFile, UriKind.Relative); mediaPlayerLauncher.Controls = MediaPlaybackControls.All; mediaPlayerLauncher.Location = MediaLocationType.Data; mediaPlayerLauncher.Show(); }
private void videoStreaming(PodcastEpisodeModel podcastEpisode) { MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher(); mediaPlayerLauncher.Media = new Uri(podcastEpisode.EpisodeDownloadUri, UriKind.Absolute); mediaPlayerLauncher.Controls = MediaPlaybackControls.All; mediaPlayerLauncher.Location = MediaLocationType.Data; mediaPlayerLauncher.Show(); }
public void deleteEpisodeFromDB(PodcastEpisodeModel episode) { var queryDelEpisode = (from e in Episodes where episode.EpisodeId.Equals(episode.EpisodeId) select episode).FirstOrDefault(); Episodes.DeleteOnSubmit(queryDelEpisode); SubmitChanges(); }
void episodeDownloadManager_PodcastEpisodeDownloadStateChanged(object source, PodcastDownloadManagerArgs args) { int episodeId = args.episodeId; PodcastEpisodeModel episode = this.EpisodeList.Items.Cast <PodcastEpisodeModel>().FirstOrDefault(e => e.EpisodeId == episodeId); if (episode != null) { episode.EpisodeDownloadState = args.downloadState; } }
private void addEpisodeToPlayableList(PodcastEpisodeModel episode) { List <PodcastEpisodeModel> tmpList = m_playableEpisodes.ToList(); tmpList.Add(episode); tmpList.Sort(CompareEpisodesByPublishDate); m_playableEpisodes = new ObservableCollection <PodcastEpisodeModel>(tmpList); m_subscription.PlayableEpisodes = m_playableEpisodes; }
private void sendDownloadStateChangedEvent(PodcastEpisodeModel episode, PodcastEpisodeModel.EpisodeDownloadStateEnum state) { if (OnPodcastEpisodeDownloadStateChanged != null) { this.OnPodcastEpisodeDownloadStateChanged(this, new PodcastDownloadManagerArgs() { downloadState = state, episodeId = episode.EpisodeId }); } }
public void play(PlaylistItem playlistItem) { using (PodcastSqlModel db = new PodcastSqlModel()) { PodcastEpisodeModel episode = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == playlistItem.EpisodeId); if (episode != null) { play(episode); } } }
private void saveEpisodeInfoToDB(PodcastEpisodeModel m_currentEpisodeDownload) { if (m_currentEpisodeDownload == null) { return; } m_currentEpisodeDownload.StoreProperty <PodcastEpisodeModel.EpisodeDownloadStateEnum>("EpisodeDownloadState", m_currentEpisodeDownload.EpisodeDownloadState); m_currentEpisodeDownload.StoreProperty <String>("EpisodeFile", m_currentEpisodeDownload.EpisodeFile); }
private void initializeCurrentlyPlayingEpisode() { // If we have an episodeId stored in local cache, this means we returned to the app and // have that episode playing. Hence, here we need to reload the episode data from the SQL. CurrentlyPlayingEpisode = updateCurrentlyPlayingEpisode(); if (CurrentlyPlayingEpisode != null) { CurrentlyPlayingEpisode.setPlaying(); } }
private int CompareEpisodesByPublishDate(PodcastEpisodeModel e1, PodcastEpisodeModel e2) { if (e1.EpisodePublished > e2.EpisodePublished) { return(-1); } else { return(1); } }
public void removeFromPlayqueue(PodcastEpisodeModel episode) { using (var db = new PlaylistDBContext()) { PlaylistItem plItem = db.Playlist.FirstOrDefault(item => item.EpisodeId == episode.EpisodeId); if (plItem != null) { removeFromPlayqueue(plItem); } } }
private void LatestEpisodeTapped(object sender, GestureEventArgs e) { PodcastEpisodeModel episode = DataContext as PodcastEpisodeModel; if (episode == null) { App.showNotificationToast("You don't subscribe to the podcast anymore."); return; } PodcastPlaybackManager.getInstance().play(episode); }