Ejemplo n.º 1
0
        private async void CheckCurrentPlayingState()
        {
            try
            {
                // Download the track list first, so that I can manipulate the data
                // to be passed to the player.
                TrackListDownloader downloader = new TrackListDownloader();
                var trackList = await downloader.GetTracksForStation(CoreViewModel.Instance.CurrentStation.JSONID);
                CoreViewModel.Instance.CurrentStation.NowPlaying = trackList.First();
                trackList.Remove(trackList.First());

                CoreViewModel.Instance.CurrentStation.TrackList = new ObservableCollection<Track>(trackList);

                // The first track in the collection tells what's playing now. It does not
                // need to be in the track history

                // Also make sure that we scrobble the track to Last.fm if necessary.
                if (CoreViewModel.Instance.CurrentAppSettings.ScrobbleOnLaunch)
                {
                    ScrobbleCurrentTrack(false);
                }

                if (BackgroundAudioPlayer.Instance.Track != null)
                {
                    if (CoreViewModel.Instance.CurrentStation != null &&
                        BackgroundAudioPlayer.Instance.Track.Title != CoreViewModel.Instance.CurrentStation.NowPlaying.FullTrackName)
                    {
                        SetAudioTrack();
                    }
                    else
                    {
                        SetAppropriateImage(false);
                    }
                }
                else
                {
                    SetAudioTrack();
                }
            }
            catch
            {
                MessageBox.Show("A problem happened, we are really sorry! Start by checking your Internet connection.",
                    "Beem", MessageBoxButton.OK);
            }
        }
Ejemplo n.º 2
0
        async void Instance_PlayStateChanged(object sender, EventArgs e)
        {
            try
            {
                Station station = StationNavigator.GetStationByName(BackgroundAudioPlayer.Instance.Track.Artist,
                    MainPageViewModel.Instance.Stations);

                if (CoreViewModel.Instance.CurrentStation != station)
                {
                    // Since the station has switched, it makes sense to stop 
                    // the recording and prompt the user to enter a name for the
                    // recorded track.
                    if (PlaybackPageViewModel.Instance.IsRecording)
                        StopRecording();

                    CoreViewModel.Instance.CurrentStation = station;
                    TrackListDownloader downloader = new TrackListDownloader();

                    var result = await downloader.GetTracksForStation(station.JSONID);
                    CoreViewModel.Instance.CurrentStation.NowPlaying = result.First();
                    result.Remove(result.First());
                    CoreViewModel.Instance.CurrentStation.TrackList = new ObservableCollection<Track>(result);
                }

                if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.TrackReady)
                    BackgroundAudioPlayer.Instance.Play();

                SetAppropriateImage(false);
            }
            catch
            {
                Debug.WriteLine("Apparently no internet and track cannot be assigned.");
            }
        }
Ejemplo n.º 3
0
        private async Task<AudioTrack> GetNextStation(string name)
        {
            try
            {
                DISettingsCache cache = Serialize.Open<DISettingsCache>("di.xml");

                List<Station> stations = Serialize.Open<List<Station>>("stationcache.xml");
                Station nextStation = StationNavigator.GetNextStation(name, stations);

                if (nextStation != null)
                {
                    TrackListDownloader downloader = new TrackListDownloader();
                    List<Track> tracks = await downloader.GetTracksForStation(nextStation.JSONID);
                    string trackName = string.Empty;

                    if (tracks != null)
                        trackName = tracks[0].FullTrackName;

                    Uri location;

                    if (cache != null && cache.IsPremiumEnabled)
                    {
                        location = new Uri(nextStation.PremiumLocation + "?" + cache.PremiumKey);
                    }
                    else
                    {
                        location = new Uri(nextStation.Location);
                    }

                    return new AudioTrack(location, trackName, nextStation.Name, string.Empty, null);
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }