Esempio n. 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());
            }
        }
Esempio n. 2
0
        public static string StringRequest(string url, string data)
        {
            var wc = new WebClient();

            if (_proxy != null)
            {
                wc.Proxy = _proxy;
            }

            wc.Encoding = System.Text.Encoding.UTF8;
            wc.Headers.Add("Content-Type", "text/plain; charset=utf8");
            wc.Headers.Add("User-Agent", _userAgent);

            string response = string.Empty;

            try
            {
                response = wc.UploadString(new Uri(url), "POST", data);
            }
            catch (WebException wex)
            {
                Log.O("StringRequest Error: " + wex.ToString());
                //Wait and Try again, just in case
                Thread.Sleep(500);
                response = wc.UploadString(new Uri(url), "POST", data);
            }

            //Log.O(response);
            return(response);
        }
Esempio n. 3
0
        public static byte[] ByteRequest(string url)
        {
            Log.O("Downloading: " + url);
            var wc = new WebClient();

            if (_proxy != null)
            {
                wc.Proxy = _proxy;
            }

            return(wc.DownloadData(new Uri(url)));
        }
Esempio n. 4
0
        public static void ByteRequestAsync(string url, DownloadDataCompletedEventHandler dataHandler)
        {
            Log.O("Downloading Async: " + url);
            var wc = new WebClient();

            if (_proxy != null)
            {
                wc.Proxy = _proxy;
            }

            wc.DownloadDataCompleted += dataHandler;
            wc.DownloadDataAsync(new Uri(url));
        }
Esempio n. 5
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
         }
     });
 }
Esempio n. 6
0
        public bool SaveConfig()
        {
            var configs = new List <string>();

            foreach (var kvp in _map)
            {
                Type t = kvp.Value.GetType();
                if (t.IsGenericType)
                {
                    foreach (var item in (Dictionary <int, string>)kvp.Value)
                    {
                        configs.Add(kvp.Key + '[' + item.Key + ']' + '|' + item.Value);
                    }
                }
                else
                {
                    configs.Add(kvp.Key + '|' + kvp.Value);
                }
            }


            bool         result = true;
            StreamWriter sw     = null;

            try
            {
                sw          = new StreamWriter(ConfigPath, false, Encoding.Unicode);
                _lastConfig = string.Empty;
                foreach (string line in configs.ToArray())
                {
                    sw.WriteLine(line);
                    _lastConfig += (line + "\r\n");
                }
            }
            catch (Exception ex)
            {
                Log.O(ex.ToString());
                result = false;
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }

            return(result);
        }
Esempio n. 7
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);
                }
            });
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
 private void _loginPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Login");
     mainBar.SetModeLogin();
 }
Esempio n. 11
0
 private void _aboutPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show About");
     mainBar.SetModeAbout();
 }
Esempio n. 12
0
 private void _settingsPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Settings");
     mainBar.SetModeSettings();
 }
Esempio n. 13
0
 private void _searchPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Search");
     mainBar.SetModeSearch();
 }
Esempio n. 14
0
 private void _stationPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Stations");
     mainBar.SetModeStationList(_player.CurrentStation != null);
 }
Esempio n. 15
0
 private void _playlistPage_Loaded(object sender, RoutedEventArgs e)
 {
     Log.O("Show Playlist");
     mainBar.SetModePlayList();
 }
Esempio n. 16
0
        public bool LoadConfig(string configData = "")
        {
            var lines = new List <string>();

            bool       result = true;
            TextReader tr     = null;

            try
            {
                if (configData == "")
                {
                    if (ConfigPath == "")
                    {
                        return(false);
                    }

                    if (!File.Exists(ConfigPath))
                    {
                        File.Create(ConfigPath).Close();
                        return(true);
                    }

                    tr = new StreamReader(ConfigPath, Encoding.Unicode);
                }
                else
                {
                    tr = new StringReader(configData);
                }
                string line = "";
                while ((line = tr.ReadLine()) != null)
                {
                    lines.Add(line);
                }

                _lastConfig = string.Empty;
                foreach (var l in lines)
                {
                    _lastConfig += (l + "\r\n");
                }
            }
            catch (Exception ex)
            {
                Log.O(ex.ToString());
                result = false;
            }
            finally
            {
                if (tr != null)
                {
                    tr.Close();
                }
            }

            if (result)
            {
                foreach (string line in lines)
                {
                    try
                    {
                        string[] split = line.Split('|');

                        if (split.Length == 2)
                        {
                            //Deal with our lists of config items saved out to keys that look like Key[ID]
                            if (split[0].Contains("["))
                            {
                                string[] splitList = split[0].Split(new [] { "[", "]" }, StringSplitOptions.None);
                                if (!_map.ContainsKey(splitList[0]))
                                {
                                    _map[splitList[0]] = new Dictionary <int, string>();
                                }
                                ((Dictionary <int, string>)_map[splitList[0]])[int.Parse(splitList[1])] = split[1];
                            }
                            //This is the normal stype of config entry - just a string
                            else
                            {
                                if (_map.ContainsKey(split[0]))
                                {
                                    _map[split[0]] = split[1]; //cascading style. newer values override old
                                }
                                else
                                {
                                    _map.Add(split[0], split[1]);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.O(ex.ToString());
                    }
                }
            }

            return(result);
        }