getInstance() public static method

public static getInstance ( ) : PodcastPlaybackManager
return PodcastPlaybackManager
Exemplo n.º 1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            this.EpisodeDownloadList.ItemsSource = m_episodeDownloadManager.EpisodeDownloadQueue;
            this.NowPlaying.SetupNowPlayingView();


            if (App.mainViewModels.LatestEpisodesListProperty.Count == 0)
            {
                this.LatestEpisodesList.Visibility = System.Windows.Visibility.Collapsed;

                if (PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode != null)
                {
                    this.NoPlayHistoryText.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    this.NoPlayHistoryText.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                this.LatestEpisodesList.Visibility = System.Windows.Visibility.Visible;
                this.NoPlayHistoryText.Visibility  = System.Windows.Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
 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();
         }
     }
 }
Exemplo n.º 3
0
        internal void SetupNowPlayingView()
        {
            this.DataContext = null;

            m_playbackManager = PodcastPlaybackManager.getInstance();

            if (m_playbackManager.CurrentlyPlayingEpisode != null)
            {
                this.Visibility = Visibility.Visible;
            }
            else
            {
                this.Visibility = Visibility.Collapsed;
                return;
            }

            if (m_currentlyPlayingEpisodeId < 0 ||
                m_playbackManager.CurrentlyPlayingEpisode.EpisodeId != m_currentlyPlayingEpisodeId)
            {
                m_currentlyPlayingEpisodeId = m_playbackManager.CurrentlyPlayingEpisode.EpisodeId;
                using (var db = new PodcastSqlModel())
                {
                    PodcastSubscriptionModel s = db.Subscriptions.First(sub => sub.PodcastId == m_playbackManager.CurrentlyPlayingEpisode.PodcastId);
                    m_podcastLogo = getLogoForSubscription(s);
                }
            }

            this.DataContext        = m_playbackManager.CurrentlyPlayingEpisode;
            this.PodcastLogo.Source = m_podcastLogo;
        }
Exemplo n.º 4
0
        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...");
                setupPlayerUIContent(PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode);
                setupUIForEpisodePlaying();
                break;

            case PlayState.Paused:
                // Player is on pause
                Debug.WriteLine("Podcast player is paused.");
                setupUIForEpisodePaused();
                break;

            case PlayState.Shutdown:
            case PlayState.Unknown:
            case PlayState.Stopped:
                // Player stopped
                Debug.WriteLine("Podcast player stopped.");
                GoBack();
                break;

            case PlayState.TrackEnded:
                break;
            }
        }
Exemplo n.º 5
0
        private void updatePlayerButtonsInApplicationBar()
        {
            if (NavigationPivot.SelectedIndex != PIVOT_INDEX_PLAYER)
            {
                return;
            }

            if (this.ApplicationBar.Buttons.Count == 4)  // This is not so nice.
            {
                return;
            }

            this.ApplicationBar.MenuItems.Clear();
            this.ApplicationBar.Buttons.Clear();

            m_playerButtons.Clear();
            if (PodcastPlaybackManager.getInstance().isCurrentlyPlaying())
            {
                m_playerButtons.Add(rewPlayerButton);
                m_playerButtons.Add(pausePlayerButton);
                m_playerButtons.Add(stopPlayerButton);
                m_playerButtons.Add(ffPlayerButton);

                foreach (ApplicationBarIconButton button in m_playerButtons)
                {
                    this.ApplicationBar.Buttons.Add(button);
                }
            }
        }
Exemplo n.º 6
0
 // Code to execute when the application is activated (brought to foreground)
 // This code will not execute when the application is first launched
 private void Application_Activated(object sender, ActivatedEventArgs e)
 {
     //          IsolatedStorageExplorer.Explorer.RestoreFromTombstone();
     CheckLicense();
     mainViewModels.PlayQueue = new System.Collections.ObjectModel.ObservableCollection <PlaylistItem>();
     PodcastPlaybackManager.getInstance().updateCurrentlyPlayingEpisode();
 }
Exemplo n.º 7
0
        public void initializePlayerUI()
        {
            PodcastEpisodeModel currentlyPlayingEpisode = PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode;

            restoreEpisodeToPlayerUI(currentlyPlayingEpisode);
            m_currentPlayerEpisode = currentlyPlayingEpisode;
            updatePlayerPosition();
        }
Exemplo n.º 8
0
        public MainView()
        {
            InitializeComponent();

            this.DataContext = App.mainViewModels;

            // Hook to the event when the download list changes, so we can update the pivot header text for the
            // download page.
            ((INotifyCollectionChanged)EpisodeDownloadList.Items).CollectionChanged += downloadListChanged;

            // Upon startup, refresh all subscriptions so we get the latest episodes for each.
            m_subscriptionsManager = PodcastSubscriptionsManager.getInstance();
            m_subscriptionsManager.OnPodcastSubscriptionsChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnPodcastSubscriptionsChanged);
            m_subscriptionsManager.refreshSubscriptions();

            // Hook to SkyDrive export events
            m_subscriptionsManager.OnOPMLExportToSkydriveChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnOPMLExportToSkydriveChanged);

            m_applicationSettings = IsolatedStorageSettings.ApplicationSettings;

            // Hook to the event when the podcast player starts playing.
            m_playbackManager = PodcastPlaybackManager.getInstance();
            m_playbackManager.OnOpenPodcastPlayer += new EventHandler(PodcastPlayer_PodcastPlayerStarted);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteStarted
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteStarted);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteFinished
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteFinished);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelPlayedCountChanged
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelPlayedCountChanged);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelAdded
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelAdded);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelRemoved
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelRemoved);

            SubscriptionsList.ItemsSource = m_subscriptions;

            if (m_subscriptions.Count > 0)
            {
                NoSubscriptionsLabel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NoSubscriptionsLabel.Visibility = Visibility.Visible;
            }

            handleShowReviewPopup();

            // This is the earliest place that we can initialize the download manager so it can show the error toast
            // which is defined in App.
            App.episodeDownloadManager = PodcastEpisodesDownloadManager.getInstance();
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        private void PlayOrderChanged(object sender, SelectionChangedEventArgs e)
        {
            ListPickerItem selectedItem = (sender as ListPicker).SelectedItem as ListPickerItem;

            if (selectedItem == null)
            {
                return;
            }

            using (var db = new PodcastSqlModel())
            {
                PodcastPlaybackManager.getInstance().sortPlaylist(db.settings().PlaylistSortOrder);
            }
        }
Exemplo n.º 11
0
        private void stopButtonClicked(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Stopped)
            {
                // We are already stopped (playback ended or something). Let's update the episode state.
                PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Downloaded;
            }
            else
            {
                StopPlayback();
            }

            showNoPlayerLayout();
            m_currentPlayerEpisode = null;
        }
Exemplo n.º 12
0
        public override Uri MapUri(Uri uri)
        {
            if (PodcastHelper.HasPodcastUri(uri))
            {
                BackgroundAudioPlayer bap = BackgroundAudioPlayer.Instance;
                var action = PodcastHelper.RetrievePodcastAction(uri);

                switch (action.Command)
                {
                case PodcastCommand.Launch:
                    // Do nothing.
                    break;

                case PodcastCommand.Pause:
                    if (bap.CanPause)
                    {
                        bap.Pause();
                    }
                    break;

                case PodcastCommand.Play:
                    if (bap.PlayerState != PlayState.Playing)
                    {
                        PodcastPlaybackManager.getInstance().startDefaultBehaviorPlayback();
                    }
                    break;

                case PodcastCommand.SkipNext:
                    if (bap.PlayerState == PlayState.Playing)
                    {
                        bap.SkipNext();
                    }
                    break;

                case PodcastCommand.SkipPrevious:
                    if (bap.PlayerState == PlayState.Playing)
                    {
                        bap.SkipPrevious();
                    }
                    break;
                }

                return(new Uri("/Views/MainView.xaml", UriKind.Relative));
            }
            // Otherwise perform normal launch.
            return(uri);
        }
Exemplo n.º 13
0
        private void PlayQueue_Click(object sender, EventArgs e)
        {
            switch (BackgroundAudioPlayer.Instance.PlayerState)
            {
            case PlayState.Playing:
                BackgroundAudioPlayer.Instance.Pause();
                break;

            case PlayState.Paused:
                BackgroundAudioPlayer.Instance.Play();
                break;

            default:
                PodcastPlaybackManager.getInstance().startPlaylistPlayback();
                break;
            }
        }
Exemplo n.º 14
0
 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();
         }
     }
 }
Exemplo n.º 15
0
        private void MenuItemAddToQueue_Click(object sender, RoutedEventArgs e)
        {
            PodcastEpisodeModel podcastEpisode = this.DataContext as PodcastEpisodeModel;

            PodcastPlaybackManager.getInstance().addToPlayqueue(podcastEpisode);
        }
Exemplo n.º 16
0
 private void stopButtonClicked(object sender, EventArgs e)
 {
     this.NowPlaying.Visibility    = System.Windows.Visibility.Collapsed;
     this.ApplicationBar.IsVisible = false;
     PodcastPlaybackManager.getInstance().stop();
 }
Exemplo n.º 17
0
        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();
        }
Exemplo n.º 18
0
        private void RemoveFromPlayQueue_Click(object sender, RoutedEventArgs e)
        {
            PlaylistItem playlistItem = (sender as MenuItem).DataContext as PlaylistItem;

            PodcastPlaybackManager.getInstance().removeFromPlayqueue(playlistItem.ItemId);
        }
Exemplo n.º 19
0
        private void PlayQueueItemTapped(object sender, RoutedEventArgs e)
        {
            int playlistItemId = (int)(sender as StackPanel).Tag;

            PodcastPlaybackManager.getInstance().playPlaylistItem(playlistItemId);
        }
Exemplo n.º 20
0
        public static void refreshEpisodesFromAudioAgent()
        {
            Debug.WriteLine("Refreshing episode information that has been updated from AudioPlayer.");

            using (var playlistdb = new PlaylistDBContext())
            {
                int playlistItemsCount            = 0;
                int listenedItemsCount            = 0;
                List <PlaylistItem> playlistItems = playlistdb.Playlist.ToList();

                playlistItemsCount = playlistItems.Count;
                using (var db = new PodcastSqlModel())
                {
                    bool deleteListened = false;
                    if (playlistItems.Count > 0)
                    {
                        deleteListened = db.settings().IsAutoDelete;
                    }

                    foreach (PlaylistItem i in playlistItems)
                    {
                        PodcastEpisodeModel e = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == i.EpisodeId);
                        if (e == null)
                        {
                            Debug.WriteLine("Warning: Could not fetch episode with ID: " + i.EpisodeId);
                            continue;
                        }

                        if (i.SavedPlayPosTick > 0)
                        {
                            Debug.WriteLine("Updating episode '" + e.EpisodeName + "' playpos to: " + i.SavedPlayPosTick);
                            e.SavedPlayPos = i.SavedPlayPosTick;

                            try
                            {
                                db.SubmitChanges();
                            }
                            catch (ChangeConflictException)
                            {
                                Debug.WriteLine("ChangeConflictException: Could not submit changes");
                            }

                            // Update play state to listened as appropriate.
                            if (e.isListened())
                            {
                                e.markAsListened(deleteListened);
                                PodcastPlaybackManager.getInstance().removeFromPlayqueue(e);
                                listenedItemsCount++;
                            }

                            e.PodcastSubscription.reloadPartiallyPlayedEpisodes();
                            e.PodcastSubscription.reloadUnplayedPlayedEpisodes();
                        }
                    }
                }

                // If all items in the play queue were listened, then we shouldn't show an episodep laying anymore.
                if (playlistItemsCount == listenedItemsCount)
                {
                    PodcastPlaybackManager.getInstance().CurrentlyPlayingEpisode = null;
                }
            }
        }
Exemplo n.º 21
0
 private void ClearPlayqueue_Click(object sender, EventArgs e)
 {
     PodcastPlaybackManager.getInstance().clearPlayQueue();
 }