Esempio n. 1
0
        public void SetPodcast(PodcastInfo podcastDefinition)
        {
            /* So we can free memory by disposing of it here later (the only reference) */
            Podcast podcast = new Podcast(podcastDefinition.URL, podcastDefinition.Name);

            _elapsedTimer?.Stop();
            PlayPause.IsEnabled = false;
            try
            {
                _currentPodcast?.Dispose();
                _currentPodcast?.Stop();

                _connectPodcastTask.Dispose();
            }
            catch { }
            _currentPodcast     = null;
            PlayPause.IsEnabled = true;

            FileName.Content = "Loading stream...";

            _connectPodcastTask = new Task(() =>
            {
                podcast.ConnectStream();
                podcast.StartPlayer();
            });

            _connectPodcastTask.GetAwaiter().OnCompleted(() =>
            {
                FileName.Content = podcast.Name;
                _currentPodcast  = podcast;
                _length          = _currentPodcast.Length.ToString(@"hh\:mm\:ss");

                PlayPause_Click(null, null);

                /* Start timer */
                _elapsedTimer          = new DispatcherTimer();
                _elapsedTimer.Interval = TimeSpan.FromMilliseconds(500);
                _elapsedTimer.Tick    += UpdatePlayTime;
                _elapsedTimer.Start();
            });
            _connectPodcastTask.Start();
        }