Пример #1
0
        private void bass_PlaybackStateChanged(object sender, BassAudioEngine.PlayState oldState,
                                               BassAudioEngine.PlayState newState)
        {
            if (PlaybackStateChanged != null)
            {
                PlaybackStateChanged(this, oldState, newState);
            }

            Log.O("Playstate: " + newState);

            Paused  = newState == BassAudioEngine.PlayState.Paused;
            Playing = newState == BassAudioEngine.PlayState.Playing;
            Stopped = newState == BassAudioEngine.PlayState.Ended || newState == BassAudioEngine.PlayState.Stopped;

            if (Playing)
            {
                _cqman.SendStatusUpdate(QueryStatusValue.Playing);
            }
            else if (Paused)
            {
                _cqman.SendStatusUpdate(QueryStatusValue.Paused);
            }
            else if (Stopped)
            {
                _cqman.SendStatusUpdate(QueryStatusValue.Stopped);
            }

            if (newState == BassAudioEngine.PlayState.Ended && CurrentStation != null)
            {
                Log.O("Song ended, playing next song.");
                RunTask(() => PlayNextSong());
            }
        }
Пример #2
0
        private void SetupLogging()
        {
            if (_config.Fields.Debug_WriteLog)
            {
                _loadingPage.UpdateStatus("Initializing logging...");
                string logFilename = "elpis{0}.log";
                if (_config.Fields.Debug_Timestamp)
                {
                    logFilename = string.Format(logFilename, DateTime.Now.ToString("_MMdd-hhmmss"));
                }
                else
                {
                    logFilename = string.Format(logFilename, "");
                }

                string path = Path.Combine(_config.Fields.Debug_Logpath, logFilename);

                if (!Directory.Exists(_config.Fields.Debug_Logpath))
                {
                    Directory.CreateDirectory(_config.Fields.Debug_Logpath);
                }

                Log.SetLogPath(path);
            }
        }
Пример #3
0
 public void StationDelete(Station station)
 {
     RunTask(() =>
     {
         bool playQuickMix = (CurrentStation == null) ? false : (station.ID == CurrentStation.ID);
         station.Delete();
         _pandora.RefreshStations();
         if (playQuickMix)
         {
             Log.O("Current station deleted, playing Quick Mix");
             PlayStation(Stations[0]);             //Set back to quickmix because current was deleted
         }
     });
 }
Пример #4
0
        private void RunTask(Action method)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    method();
                }
                catch (PandoraException pex)
                {
                    Log.O(pex.Fault.ToString() + ": " + pex);
                    SendPandoraError(pex.Fault, pex);
                }
                catch (Exception ex)
                {
                    Log.O(ex.ToString());

                    SendPandoraError(ErrorCodes.UNKNOWN_ERROR, ex);
                }
            });
        }
Пример #5
0
        private void PlayNextSong(int retry = 2)
        {
            if (!_playNext || retry < 2)
            {
                _playNext = true;
                Song song = null;
                if (LoadingNextSong != null)
                {
                    Log.O("Loading next song.");
                    LoadingNextSong(this);
                }

                try
                {
                    song = _playlist.NextSong();
                }
                catch (PandoraException pex)
                {
                    _playNext = false;
                    if (pex.Fault == ErrorCodes._END_OF_PLAYLIST)
                    {
                        Stop();
                        return;
                    }

                    throw;
                }

                Log.O("Play: " + song);
                if (SongStarted != null)
                {
                    SongStarted(this, song);
                }

                try
                {
                    _bass.Play(song.AudioUrl, song.FileGain);
                    _cqman.SendSongUpdate(song);
                    //_cqman.SendStatusUpdate(QueryStatusValue.Playing);
                }
                catch (BassStreamException ex)
                {
                    if (ex.ErrorCode == Un4seen.Bass.BASSError.BASS_ERROR_FILEOPEN)
                    {
                        _playlist.DoReload();
                    }
                    if (retry > 0)
                    {
                        PlayNextSong(retry - 1);
                    }
                    else
                    {
                        Stop();
                        _cqman.SendStatusUpdate(QueryStatusValue.Error);
                        throw new PandoraException(ErrorCodes.STREAM_ERROR, ex);
                    }
                }
                finally
                {
                    _playNext = false;
                }

                _playNext = false;
            }
        }
Пример #6
0
        private void FinalLoad()
        {
            Version ver = Assembly.GetEntryAssembly().GetName().Version;

            if (_config.Fields.Elpis_Version == null || _config.Fields.Elpis_Version < ver)
            {
                _loadingPage.UpdateStatus("Running update logic...");

                string oldVer = _config.Fields.Elpis_Version.ToString();

                _config.Fields.Elpis_Version = ver;
                _config.SaveConfig();

#if APP_RELEASE
                var post = new PostSubmitter(ReleaseData.AnalyticsPostURL);

                post.Add("guid", _config.Fields.Elpis_InstallID);
                post.Add("curver", oldVer);
                post.Add("newver", _config.Fields.Elpis_Version.ToString());
                post.Add("osver", SystemInfo.GetWindowsVersion());

                try
                {
                    post.Send();
                }
                catch (Exception ex)
                {
                    Log.O(ex.ToString());
                }
#endif
            }

            _loadingPage.UpdateStatus("Loading audio engine...");
            try
            {
                _player = new Player();
                _player.Initialize(_bassRegEmail, _bassRegKey); //TODO - put this in the login sequence?
                if (_config.Fields.Proxy_Address != string.Empty)
                {
                    _player.SetProxy(_config.Fields.Proxy_Address, _config.Fields.Proxy_Port,
                                     _config.Fields.Proxy_User, _config.Fields.Proxy_Password);
                }
            }
            catch (Exception ex)
            {
                ShowError(ErrorCodes.ENGINE_INIT_ERROR, ex);
                return;
            }

            LoadLastFM();

            _player.AudioFormat = _config.Fields.Pandora_AudioFormat;
            _player.SetStationSortOrder(_config.Fields.Pandora_StationSortOrder);
            _player.Volume      = _config.Fields.Elpis_Volume;
            _player.PauseOnLock = _config.Fields.Elpis_PauseOnLock;
            _player.MaxPlayed   = _config.Fields.Elpis_MaxHistory;

            //_player.ForceSSL = _config.Fields.Misc_ForceSSL;


            _loadingPage.UpdateStatus("Setting up cache...");
            string cachePath = Path.Combine(Config.ElpisAppData, "Cache");
            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }
            _player.ImageCachePath = cachePath;

            _loadingPage.UpdateStatus("Starting Web Server...");

            startWebServer();

            _loadingPage.UpdateStatus("Setting up UI...");

            this.Dispatch(() => {
                _keyHost = new HotKeyHost(this);
                ConfigureHotKeys();
            });

            //this.Dispatch(SetupJumpList);

            this.Dispatch(SetupNotifyIcon);

            this.Dispatch(() => mainBar.DataContext = _player); //To bind playstate

            this.Dispatch(SetupPages);
            this.Dispatch(SetupUIEvents);
            this.Dispatch(SetupPageEvents);

            if (_config.Fields.Login_AutoLogin &&
                (!string.IsNullOrEmpty(_config.Fields.Login_Email)) &&
                (!string.IsNullOrEmpty(_config.Fields.Login_Password)))
            {
                _player.Connect(_config.Fields.Login_Email, _config.Fields.Login_Password);
            }
            else
            {
                transitionControl.ShowPage(_loginPage);
            }

            this.Dispatch(() => mainBar.Volume = _player.Volume);

            _finalComplete = true;
        }
Пример #7
0
 private void _loginPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Login");
     mainBar.SetModeLogin();
 }
Пример #8
0
 private void _aboutPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show About");
     mainBar.SetModeAbout();
 }
Пример #9
0
 private void _settingsPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Settings");
     mainBar.SetModeSettings();
 }
Пример #10
0
 private void _searchPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Search");
     mainBar.SetModeSearch();
 }
Пример #11
0
 private void _stationPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Stations");
     mainBar.SetModeStationList(_player.CurrentStation != null);
 }
Пример #12
0
 private void _playlistPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Playlist");
     mainBar.SetModePlayList();
 }