private void SetAudioFormat(ref object value)
        {
            try
            {
                object resultObject;
                string resultvalue, resulttext;

                CFControls.CFListViewItem[] audioFormatItems = new CFControls.CFListViewItem[3];
                audioFormatItems[0] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.AAC_PLUS), AudioFormats.AAC_PLUS.ToString(), 0, false, (object)AudioFormats.AAC_PLUS);
                audioFormatItems[1] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.MP3), AudioFormats.MP3.ToString(), 0, false, (object)AudioFormats.MP3);
                audioFormatItems[2] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.MP3_HIFI), AudioFormats.MP3_HIFI.ToString(), 0, false, (object)AudioFormats.MP3_HIFI);

                AudioFormats audioFormat = AudioFormats.MP3;

                try
                {
                    audioFormat = (AudioFormats)Enum.Parse(typeof(AudioFormats), this.pluginConfig.ReadField("/APPCONFIG/AUDIOFORMAT"));
                }
                catch { }

                //TODO: Pass in current value so the list shows the correct item selected initially, this doesn't seem to work as-is
                DialogResult dialogResult = this.CF_systemDisplayDialog(CF_Dialogs.FileBrowser, this.pluginLang.ReadField("/APPLANG/SETUP/AUDIOFORMAT"), null, audioFormat.ToString(), out resultvalue, out resulttext, out resultObject, audioFormatItems, false, true, false, false, false, false, 1);

                if (dialogResult == DialogResult.OK)
                {
                    audioFormat = (AudioFormats)resultObject;

                    // save user value, note this does not save to file yet, as this should only be done when user confirms settings
                    // being overwritten when they click the "Save" button.  Saving is done internally by the CFSetup instance if
                    // pluginConfig and pluginLang were properly set before callin CF_initSetup().
                    this.pluginConfig.WriteField("/APPCONFIG/AUDIOFORMAT", audioFormat.ToString());

                    // Display new value on Settings Screen button
                    ButtonValue[(int)value] = resulttext;

                    if (audioFormat == AudioFormats.MP3_HIFI)
                    {
                        CFDialogParams dialogParams = new CFDialogParams("High quality audio is only available to Pandora One subscribers. If you are not a subscriber regular quality will be used instead.");
                        this.CF_displayDialog(CF_Dialogs.OkBox, dialogParams);
                    }
                    else if (audioFormat == AudioFormats.AAC_PLUS)
                    {
                        System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
                        string bassAacAssemblyPath          = System.IO.Path.GetDirectoryName(assembly.Location) + "\\bass_aac.dll";

                        if (!File.Exists(bassAacAssemblyPath))
                        {
                            CFDialogParams dialogParams = new CFDialogParams("Centrafuse does not natively support the AAC audio format which is used by the mobile quality setting. To enable mobile quality playback you need to install the bass_aac.dll audio extension which can be downloaded from www.un4seen.com. Place the DLL in the Centrafuse directory. If you do not install this library you will not be able to listen to Pandora using the mobile quality setting.");
                            this.CF_displayDialog(CF_Dialogs.OkBoxBig, dialogParams);
                        }
                    }
                }
            }
            catch (Exception errmsg) { CFTools.writeError(errmsg.Message, errmsg.StackTrace); }
        }
Exemple #2
0
        private void LoadAlbumSearch()
        {
            if (CheckLoggedInAndOnline())
            {
                CFDialogParams  searchDialogParams = new CFDialogParams("Search by album name");
                CFDialogResults results            = new CFDialogResults();
                DialogResult    result             = CF_displayDialog(CF_Dialogs.OSK, searchDialogParams, results);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string searchText = results.resultvalue;
                    CF_systemCommand(CF_Actions.SHOWINFO, "Searching...");
                    ThreadPool.QueueUserWorkItem(delegate(object param)
                    {
                        try
                        {
                            var search = SpotifySession.SearchAlbums(searchText, 0, 20);

                            SleepUntilTrue(() => search.IsComplete);

                            List <IAlbum> albums = new List <IAlbum>();
                            foreach (var album in search.Albums)
                            {
                                if (album.IsAvailable)
                                {
                                    albums.Add(album);
                                }
                            }
                            search.Dispose();
                            var table = LoadAlbumsIntoTable(albums, false);

                            this.ParentForm.BeginInvoke(new MethodInvoker(delegate()
                            {
                                CF_systemCommand(CF_Actions.HIDEINFO);
                                SwitchToTab(Tabs.Search, GroupingType.Albums, table, "Search", null, true);
                            }));
                        }
                        catch (Exception ex)
                        {
                            this.ParentForm.BeginInvoke(new MethodInvoker(() =>
                            {
                                CF_systemCommand(CF_Actions.HIDEINFO);
                                WriteError(ex);
                                CF_displayMessage(ex.Message);
                            }));
                        }
                    });
                }
            }
        }
        private void LoadAlbumSearch()
        {
            if (CheckLoggedInAndOnline())
            {
                CFDialogParams searchDialogParams = new CFDialogParams("Search by album name");
                CFDialogResults results = new CFDialogResults();
                DialogResult result = CF_displayDialog(CF_Dialogs.OSK, searchDialogParams, results);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string searchText = results.resultvalue;
                    CF_systemCommand(CF_Actions.SHOWINFO, "Searching...");
                    ThreadPool.QueueUserWorkItem(delegate(object param)
                    {
                        try
                        {
                            var search = SpotifySession.SearchAlbums(searchText, 0, 20);

                            SleepUntilTrue(() => search.IsComplete);

                            List<IAlbum> albums = new List<IAlbum>();
                            foreach (var album in search.Albums)
                            {
                                if (album.IsAvailable)
                                {
                                    albums.Add(album);
                                }
                            }
                            search.Dispose();
                            var table = LoadAlbumsIntoTable(albums, false);

                            this.ParentForm.BeginInvoke(new MethodInvoker(delegate()
                            {
                                CF_systemCommand(CF_Actions.HIDEINFO);
                                SwitchToTab(Tabs.Search, GroupingType.Albums, table, "Search", null, true);
                            }));
                        }
                        catch (Exception ex)
                        {
                            this.ParentForm.BeginInvoke(new MethodInvoker(() =>
                            {
                                CF_systemCommand(CF_Actions.HIDEINFO);
                                WriteError(ex);
                                CF_displayMessage(ex.Message);
                            }));
                        }
                    });
                }
            }
        }
        private void ClearFavorites(ref object value)
        {
            try
            {
                CFDialogParams dialogParams = new CFDialogParams();
                dialogParams.displaytext = "Are you sure you want to clear your favorite stations?";
                DialogResult dialogResult = CF_displayDialog(CF_Dialogs.YesNo, dialogParams);

                if (dialogResult == DialogResult.OK)
                {
                    this.pluginConfig.WriteField("/APPCONFIG/FAVORITES", String.Empty);
                }
            }
            catch (Exception errmsg) { CFTools.writeError(errmsg.Message, errmsg.StackTrace); }
        }
Exemple #5
0
        private void SetLocation(ref object value)
        {
            string location = GetLocation();

            CFDialogParams dialogParams = new CFDialogParams("Choose a folder for Spotify data", location);

            dialogParams.browseable       = true;
            dialogParams.enablesubactions = true;
            dialogParams.showfiles        = false;

            CFDialogResults results = new CFDialogResults();

            if (this.CF_displayDialog(CF_Dialogs.FileBrowser, dialogParams, results) == DialogResult.OK)
            {
                string newPath = results.resultvalue;
                this.pluginConfig.WriteField("/APPCONFIG/LOCATION", newPath);
                ButtonValue[(int)value] = newPath;
            }
        }
        private void ClearFavorites(ref object value)
        {
            try
            {
                CFDialogParams dialogParams = new CFDialogParams();
                dialogParams.displaytext = "Are you sure you want to clear your favorite stations?";
                DialogResult dialogResult = CF_displayDialog(CF_Dialogs.YesNo, dialogParams);

                if (dialogResult == DialogResult.OK)
                    this.pluginConfig.WriteField("/APPCONFIG/FAVORITES", String.Empty);
            }
            catch (Exception errmsg) { CFTools.writeError(errmsg.Message, errmsg.StackTrace); }
        }
        private void SetLocation(ref object value)
        {
            string location = GetLocation();

            CFDialogParams dialogParams = new CFDialogParams("Choose a folder for Spotify data", location);
            dialogParams.browseable = true;
            dialogParams.enablesubactions = true;
            dialogParams.showfiles = false;

            CFDialogResults results = new CFDialogResults();
            if (this.CF_displayDialog(CF_Dialogs.FileBrowser, dialogParams, results) == DialogResult.OK)
            {
                string newPath = results.resultvalue;
                this.pluginConfig.WriteField("/APPCONFIG/LOCATION", newPath);
                ButtonValue[(int)value] = newPath;
            }
        }
        private void SetAudioFormat(ref object value)
        {
            try
            {
                object resultObject;
                string resultvalue, resulttext;

                CFControls.CFListViewItem[] audioFormatItems = new CFControls.CFListViewItem[3];
                audioFormatItems[0] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.AAC_PLUS), AudioFormats.AAC_PLUS.ToString(), 0, false, (object)AudioFormats.AAC_PLUS);
                audioFormatItems[1] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.MP3), AudioFormats.MP3.ToString(), 0, false, (object)AudioFormats.MP3);
                audioFormatItems[2] = new CFControls.CFListViewItem(GetAudioFormatDisplay(AudioFormats.MP3_HIFI), AudioFormats.MP3_HIFI.ToString(), 0, false, (object)AudioFormats.MP3_HIFI);

                AudioFormats audioFormat = AudioFormats.MP3;

                try
                {
                    audioFormat = (AudioFormats)Enum.Parse(typeof(AudioFormats), this.pluginConfig.ReadField("/APPCONFIG/AUDIOFORMAT"));
                }
                catch { }

                //TODO: Pass in current value so the list shows the correct item selected initially, this doesn't seem to work as-is
                DialogResult dialogResult = this.CF_systemDisplayDialog(CF_Dialogs.FileBrowser, this.pluginLang.ReadField("/APPLANG/SETUP/AUDIOFORMAT"), null, audioFormat.ToString(), out resultvalue, out resulttext, out resultObject, audioFormatItems, false, true, false, false, false, false, 1);

                if (dialogResult == DialogResult.OK)
                {
                    audioFormat = (AudioFormats)resultObject;

                    // save user value, note this does not save to file yet, as this should only be done when user confirms settings
                    // being overwritten when they click the "Save" button.  Saving is done internally by the CFSetup instance if
                    // pluginConfig and pluginLang were properly set before callin CF_initSetup().
                    this.pluginConfig.WriteField("/APPCONFIG/AUDIOFORMAT", audioFormat.ToString());

                    // Display new value on Settings Screen button
                    ButtonValue[(int)value] = resulttext;

                    if (audioFormat == AudioFormats.MP3_HIFI)
                    {
                        CFDialogParams dialogParams = new CFDialogParams("High quality audio is only available to Pandora One subscribers. If you are not a subscriber regular quality will be used instead.");
                        this.CF_displayDialog(CF_Dialogs.OkBox, dialogParams);
                    }
                    else if (audioFormat == AudioFormats.AAC_PLUS)
                    {
                        System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
                        string bassAacAssemblyPath = System.IO.Path.GetDirectoryName(assembly.Location) + "\\bass_aac.dll";

                        if (!File.Exists(bassAacAssemblyPath))
                        {
                            CFDialogParams dialogParams = new CFDialogParams("Centrafuse does not natively support the AAC audio format which is used by the mobile quality setting. To enable mobile quality playback you need to install the bass_aac.dll audio extension which can be downloaded from www.un4seen.com. Place the DLL in the Centrafuse directory. If you do not install this library you will not be able to listen to Pandora using the mobile quality setting.");
                            this.CF_displayDialog(CF_Dialogs.OkBoxBig, dialogParams);
                        }
                    }
                }
            }
            catch (Exception errmsg) { CFTools.writeError(errmsg.Message, errmsg.StackTrace); }
        }
        private void StationSearch()
        {
            WriteLog();

            if (_clientIsBusy)
                return;

            if (!EnsureAuthenticated("StationSearch"))
                return;

            CFDialogParams dialogParams = new CFDialogParams();
            dialogParams.displaytext = "Enter the name of an artist or song";
            CFDialogResults dialogResults = new CFDialogResults();

            DialogResult dialogResult = CF_displayDialog(CF_Dialogs.OSK, dialogParams, dialogResults);

            if (dialogResult == DialogResult.OK && !IsNullOrWhiteSpace(dialogResults.resultvalue))
            {
                CF_systemCommand(CF_Actions.SHOWINFO, "Searching...");
                _clientIsBusy = true;
                _pandoraClient.SearchAsync(dialogResults.resultvalue);
            }
        }
        private void SubmitFeedback(Song song, Ratings rating)
        {
            WriteLog();

            if (_clientIsBusy)
                return;

            if (!EnsureAuthenticated("SubmitFeedback"))
                return;

            if (song == null)
                return;

            if (rating == Ratings.Dislike)
            {
                CFDialogParams dialogParams = new CFDialogParams();
                dialogParams.displaytext = "Are you sure you want to dislike this song?";
                DialogResult dialogResult = CF_displayDialog(CF_Dialogs.YesNo, dialogParams);

                if (dialogResult != DialogResult.OK)
                    return;
            }

            _clientIsBusy = true;
            _songToRate = song;
            _ratingToSubmit = rating;
            _pandoraClient.SubmitFeedbackAsync(song, rating);
        }
        private void ShowSearchResults(List<SearchResult> searchResults)
        {
            WriteLog();

            if (searchResults == null || searchResults.Count == 0)
                return;

            searchResults.Sort(delegate(SearchResult searchResult1, SearchResult searchResult2)
            {
                if (searchResult1.SearchResultType == searchResult2.SearchResultType)
                    return 0;
                else if (searchResult1.SearchResultType == SearchResultTypes.Artist &&
                            searchResult2.SearchResultType == SearchResultTypes.Song)
                    return -1;
                else if (searchResult1.SearchResultType == SearchResultTypes.Song &&
                            searchResult2.SearchResultType == SearchResultTypes.Artist)
                    return 1;
                else
                    return 0; //Shouldn't happen
            });

            CFControls.CFListViewItem[] listItems = new CFControls.CFListViewItem[searchResults.Count];

            for (int i = 0; i < searchResults.Count; i++)
                listItems[i] = new CFControls.CFListViewItem(searchResults[i].ResultText, searchResults[i].MusicId, 0, false, searchResults[i] as object);

            CFDialogParams dialogParams = new CFDialogParams();
            CFDialogResults dialogResults = new CFDialogResults();
            dialogParams.displaytext = "Choose a result from the list to create a station.";
            dialogParams.listitems = listItems;

            DialogResult dialogResult = CF_displayDialog(CF_Dialogs.FileBrowser, dialogParams, dialogResults);

            if (dialogResult != DialogResult.OK)
                return;

            if (!EnsureAuthenticated("CreateStation"))
                return;

            _clientIsBusy = true;
            _pandoraClient.CreateStationAsync(dialogResults.resultvalue);
        }
        private void PlayNextSong()
        {
            WriteLog();

            if (String.IsNullOrEmpty(_currentStationId))
                CF_displayMessage("Please select a station first.");
            else if (_songs.Count == 0)
            {
                if (!EnsureAuthenticated("PlayNextSong"))
                    return;

                _clientIsBusy = true;
                _afterCallAction = "PlayNextSong";
                _pandoraClient.RetrieveSongsAsync(_currentStationId, GetAudioFormat());
            }
            else
            {
                _timer.Stop();

                CF_controlAudioStream(_audioStream, CF_AudioAction.Stop);
                CF_controlAudioStream(_audioStream, CF_AudioAction.Free);
                CF_setPlayPauseButton(true, _zone);

                _currentSong = _songs.Dequeue();

                CF_updateText("CurrentSongInfo", String.Format("{0} / {1} / {2}", _currentSong.SongTitle, _currentSong.ArtistSummary, _currentSong.AlbumTitle));

                if (_currentSong.Like)
                    CF_setPictureImage("ThumbsUpActive", _activeLikeIcon);
                else
                    CF_setPictureImage("ThumbsUpActive", null);

                CF_setPictureImage("AlbumArt", _defaultAlbumArt);

                string audioUrl = _currentSong.AudioUrl;

                try
                {
                    //HACK - The audio complete callback handler apparently isn't implemented
                    //so we pass null and use a timer to check manually... so lame!
                    _audioStream = CF_playAudioStream(audioUrl, null);
                    CF_setPlayPauseButton(false, _zone);
                }
                catch (Exception ex)
                {
                    _timer.Stop();
                    WriteLog("Unable to play audio stream.", ex);
                    CFDialogParams dialogParams = new CFDialogParams();
                    dialogParams.displaytext = String.Format("{0} Plugin: Unable to play audio stream ({1})", _pluginName, ex.Message);
                    CF_displayDialog(CF_Dialogs.OkBoxBig, dialogParams);
                    return;
                }

                _timer.Start();

                try
                {
                    if (!String.IsNullOrEmpty(_currentSong.ArtRadio))
                    {
                        string imagePath = GetLocalAlbumArtFileName(_currentSong.ArtRadio);

                        if (File.Exists(imagePath))
                            CF_setPictureImage("AlbumArtPicture", Image.FromFile(imagePath));
                        else
                            _albumArtWebClient.DownloadFileAsync(new Uri(_currentSong.ArtRadio), imagePath, _currentSong);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog("Error retrieving album art.", ex);
                }

                if (_songs.Count < 2)
                {
                    if (!EnsureAuthenticated())
                        return;

                    _clientIsBusy = true;
                    _afterCallAction = null;
                    _pandoraClient.RetrieveSongsAsync(_currentStationId, GetAudioFormat());
                }
            }
        }
        private void DeleteStation(string stationId)
        {
            WriteLog();

            if (_clientIsBusy)
                return;

            if (!EnsureAuthenticated("DeleteStation"))
                return;

            Station station = _stations.Find(delegate(Station item)
            {
                return item.StationId == stationId;
            });

            if (station == null)
                return;

            CFDialogParams dialogParams = new CFDialogParams();
            dialogParams.displaytext = String.Format("{0}{1}{1}Are you sure you want to delete this station?", station.StationName, Environment.NewLine);
            DialogResult result = CF_displayDialog(CF_Dialogs.YesNo, dialogParams);

            if (result == DialogResult.OK)
            {
                _clientIsBusy = true;
                _stationIdToRemove = station.StationId;
                _pandoraClient.RemoveStationAsync(station.StationId);
            }
        }
        private void _pandoraClient_ExceptionReceived(object sender, EventArgs<Exception> e)
        {
            WriteLog();

            CF_systemCommand(CF_Actions.HIDEINFO);

            _lastAuthenticated = DateTime.MinValue;
            _afterCallAction = null;

            WriteLog("An exception occured while calling the Pandora client.", e.Value);

            if (e.Value.Data != null)
            {
                foreach (DictionaryEntry entry in e.Value.Data)
                    WriteLog(String.Format("Additional Info ({0}): {1}", entry.Key, entry.Value));
            }

            if (e.Value.InnerException != null)
                WriteLog("Inner Exception", e.Value.InnerException);

            CFDialogParams dialogParams = new CFDialogParams();
            dialogParams.displaytext = String.Format("{0} Plugin Error:{1}{2}", _pluginName, Environment.NewLine, e.Value.Message);
            CF_displayDialog(CF_Dialogs.OkBoxBig, dialogParams);

            _clientIsBusy = false;
        }
        private void ToggleGuest()
        {
            WriteLog();

            if (_guest)
            {
                CFDialogParams dialogParams = new CFDialogParams();
                dialogParams.displaytext = String.Format("Are you sure you want to logoff of the guest account {0} ?", _userName);
                DialogResult dialogResult = CF_displayDialog(CF_Dialogs.YesNo, dialogParams);

                if (dialogResult == DialogResult.OK)
                {
                    EndSession();
                    _guest = false;
                    CF_setPictureImage("GuestActive", null);

                    //Load the stored credentials, favorites, etc back in
                    LoadSettings();

                    RefreshStations();
                }
            }
            else
            {
                string guestUsername = null;
                string guestPassword = null;

                CFDialogParams dialogParams = new CFDialogParams();
                CFDialogResults dialogResults = new CFDialogResults();
                DialogResult dialogResult;

                dialogParams.displaytext = this.pluginLang.ReadField("/APPLANG/PANDORA/USERNAMEPROMPT");
                dialogResult = CF_displayDialog(CF_Dialogs.OSK, dialogParams, dialogResults);

                if (dialogResult == DialogResult.Cancel)
                    return;

                if (IsNullOrWhiteSpace(dialogResults.resultvalue))
                {
                    CF_displayMessage("Invalid user name.");
                    return;
                }

                guestUsername = dialogResults.resultvalue;

                //UGH! More SDK inconsistencies... passing "PASSWORD" as param2 here doesn't invoke the password
                //masking feature, so I have to use the full blown CF_systemDisplayDialog method instead. Lame.
                //dialogParams.displaytext = this.pluginLang.ReadField("/APPLANG/PANDORA/PASSWORDPROMPT");
                //dialogParams.param2 = "PASSWORD";
                //dialogResult = CF_displayDialog(CF_Dialogs.OSK, dialogParams, dialogResults);
                object tempObject;
                string resultValue, resultText;
                dialogResult = this.CF_systemDisplayDialog(CF_Dialogs.OSK, this.pluginLang.ReadField("/APPLANG/PANDORA/PASSWORDPROMPT"), String.Empty, "PASSWORD", out resultValue, out resultText, out tempObject, null, true, true, true, true, false, false, 1);

                if (dialogResult == DialogResult.Cancel)
                    return;

                if (IsNullOrWhiteSpace(resultValue))
                {
                    CF_displayMessage("Invalid password.");
                    return;
                }

                guestPassword = resultValue;

                EndSession();
                _guest = true;
                CF_setPictureImage("GuestActive", _activeGuestIcon);
                _userName = guestUsername;
                _password = guestPassword;
                RefreshStations();
            }
        }