getIntance() public static method

public static getIntance ( ) : PodcastPlayerControl
return PodcastPlayerControl
コード例 #1
0
        private void audioStreaming(PodcastEpisodeModel podcastEpisode)
        {
            PodcastPlayerControl player = PodcastPlayerControl.getIntance();

            player.streamEpisode(podcastEpisode);
        }
コード例 #2
0
        public void play(PodcastEpisodeModel episode, bool startedFromPlayQueue = false)
        {
            if (episode == null)
            {
                Debug.WriteLine("Warning: Trying to play a NULL episode.");
                return;
            }

            Debug.WriteLine("Starting playback for episode: ");
            Debug.WriteLine(" Name: " + episode.EpisodeName);
            Debug.WriteLine(" File: " + episode.EpisodeFile);
            Debug.WriteLine(" Location: " + episode.EpisodeDownloadUri);

            // We have another episode currently playing, and we switch the episode that we are playing.
            if (CurrentlyPlayingEpisode != null &&
                (episode.EpisodeId != CurrentlyPlayingEpisode.EpisodeId))
            {
                CurrentlyPlayingEpisode.setNoPlaying();

                try
                {
                    CurrentlyPlayingEpisode.SavedPlayPos = BackgroundAudioPlayer.Instance.Position.Ticks;
                }
                catch (Exception)
                {
                    Debug.WriteLine("Could not set saved play pos; not available.");
                    CurrentlyPlayingEpisode.SavedPlayPos = 0;
                }

                using (var db = new PodcastSqlModel())
                {
                    PodcastEpisodeModel savingEpisode = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == CurrentlyPlayingEpisode.EpisodeId);
                    savingEpisode.SavedPlayPos = CurrentlyPlayingEpisode.SavedPlayPos;
                    db.SubmitChanges();
                }
            }

            if (startedFromPlayQueue)
            {
                if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Paused ||
                    (CurrentlyPlayingEpisode != null &&
                     CurrentlyPlayingEpisode.EpisodeId != episode.EpisodeId))
                {
                    CurrentlyPlayingEpisode = episode;
                }
            }
            else
            {
                CurrentlyPlayingEpisode = episode;

                // Clear play queue (yes) when we start playback from episode listing.
                // And we clear the queue after the current episode is being set, so that we don't delete the currently
                // playing one.
                clearPlayQueue();
            }

            // Play locally from a downloaded file.
            if (CurrentlyPlayingEpisode != null &&
                CurrentlyPlayingEpisode.EpisodeDownloadState == PodcastEpisodeModel.EpisodeDownloadStateEnum.Downloaded)
            {
                PodcastPlayerControl player = PodcastPlayerControl.getIntance();
                CurrentlyPlayingEpisode.setPlaying();
                CurrentlyPlayingEpisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Playing;
                player.playEpisode(CurrentlyPlayingEpisode);
            }
            else
            {
                // Stream it if not downloaded.
                if (isAudioPodcast(CurrentlyPlayingEpisode))
                {
                    CurrentlyPlayingEpisode.setPlaying();
                    audioStreaming(CurrentlyPlayingEpisode);
                    CurrentlyPlayingEpisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Streaming;
                }
                else
                {
                    PodcastPlayerControl player = PodcastPlayerControl.getIntance();
                    player.StopPlayback();
                    videoStreaming(episode);
                    CurrentlyPlayingEpisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Streaming;
                }
            }

            // Always open the player view.
            var handler = OnOpenPodcastPlayer;

            if (handler != null)
            {
                OnOpenPodcastPlayer(this, new EventArgs());
            }

            var handlerStartedPlaying = OnPodcastStartedPlaying;

            if (handlerStartedPlaying != null)
            {
                if (isAudioPodcast(episode))
                {
                    OnPodcastStartedPlaying(this, new EventArgs());
                }
            }

            App.mainViewModels.PlayQueue = new System.Collections.ObjectModel.ObservableCollection <PlaylistItem>(); // Notify playlist changed.
        }