private void SetCurrentSongUserRatingFromServer(int serverValue)
        {
            int rating = serverValue / 20;

            _CurrentSongUserRating  = rating;
            _ratingUpdatedForSongID = CurrentItemID;
            PropertyChanged.RaiseOnUIThread(this, "CurrentSongUserRating");
        }
示例#2
0
        protected void SendPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            PropertyChanged.RaiseOnUIThread(this, propertyName);
        }
示例#3
0
        protected void SendVolumePropertyChanged()
        {
            PropertyChanged.RaiseOnUIThread("CurrentVolume", "BindableVolume");

            lock (Speakers)
            {
                foreach (AirPlaySpeaker speaker in Speakers)
                {
                    speaker.UpdateBindableVolume();
                }
            }
        }
示例#4
0
 private void SendTrackTimePropertyChanged()
 {
     PropertyChanged.RaiseOnUIThread(this,
                                     "TrackTimeTotal",
                                     "TrackTimeRemaining",
                                     "CurrentTrackTimeRemaining",
                                     "CurrentTrackTimePosition",
                                     "CurrentTrackTimePercentage",
                                     "CurrentTrackTimePositionString",
                                     "CurrentTrackTimeRemainingString",
                                     "CurrentTrackTimePositionOrPausedString");
 }
示例#5
0
        internal void UpdateBindableVolume()
        {
            lock (Server.Speakers)
            {
                // If there are no other AirPlay speakers enabled, just return the server volume
                if (!Server.Speakers.Any(s => s != this && s.Active))
                {
                    _BindableVolume = Server.CurrentVolume;
                }

                else if (Server.CurrentVolume == 100)
                {
                    _BindableVolume = Volume;
                }

                else
                {
                    double volumePercentage = (double)Volume / 100;
                    _BindableVolume = (int)((double)Server.CurrentVolume * volumePercentage);
                }
            }

            PropertyChanged.RaiseOnUIThread(this, "BindableVolume");
        }
 private void ClearCurrentSongUserRating()
 {
     _CurrentSongUserRating  = 0;
     _ratingUpdatedForSongID = 0;
     PropertyChanged.RaiseOnUIThread(this, "CurrentSongUserRating");
 }
        protected async Task <bool> GetPlayStatusUpdateAsync(CancellationToken cancellationToken)
        {
            // Do not pass the cancellation token to the HTTP request since cancelling a request will cause iTunes to close the current session.
            DACPRequest request = new DACPRequest("/ctrl-int/1/playstatusupdate");

            request.QueryParameters["revision-number"] = _playStatusRevisionNumber.ToString();

            try
            {
                var response = await SubmitRequestAsync(request).ConfigureAwait(false);

                // Do we still need to process this response?
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                // Process response
                ThreadUtility.RunOnUIThread(() =>
                {
                    timerTrackTimeUpdate.Stop();
                });

                var nodes = DACPNodeDictionary.Parse(response.Nodes);
                _playStatusRevisionNumber = nodes.GetInt("cmsr");

                int oldSongID = CurrentItemID;

                if (nodes.ContainsKey("canp"))
                {
                    // Current song and container IDs
                    byte[] value = nodes["canp"];

                    byte[] dbID            = { value[0], value[1], value[2], value[3] };
                    byte[] containerID     = { value[4], value[5], value[6], value[7] };
                    byte[] containerItemID = { value[8], value[9], value[10], value[11] };
                    byte[] itemID          = { value[12], value[13], value[14], value[15] };
                    CurrentDatabaseID      = dbID.GetInt32Value();
                    CurrentContainerID     = containerID.GetInt32Value();
                    CurrentContainerItemID = containerItemID.GetInt32Value();
                    CurrentItemID          = itemID.GetInt32Value();
                }
                else
                {
                    CurrentDatabaseID      = 0;
                    CurrentContainerID     = 0;
                    CurrentContainerItemID = 0;
                    CurrentItemID          = 0;
                }
                CurrentSongName          = nodes.GetString("cann");
                CurrentArtist            = nodes.GetString("cana");
                CurrentAlbum             = nodes.GetString("canl");
                CurrentAlbumPersistentID = (UInt64)nodes.GetLong("asai");
                PlayState = (PlayStates)nodes.GetByte("caps");

                // Shuffle
                int caas = nodes.GetInt("caas");
                IsShuffleAvailable = (caas & (1 << 1)) != 0;
                ShuffleState       = nodes.GetBool("cash");

                // Repeat
                int caar = nodes.GetInt("caar");
                IsRepeatOneAvailable = (caar & (1 << 1)) != 0;
                IsRepeatAllAvailable = (caar & (1 << 2)) != 0;
                RepeatState          = (RepeatStates)nodes.GetByte("carp");

                CurrentMediaKind = nodes.GetInt("cmmk");
                ShowUserRating   = nodes.GetBool("casu");

                // Track length (ms)
                TrackTimeTotal = nodes.GetInt("cast");
                // Remaining track length (ms)
                TrackTimeRemaining = nodes.GetNullableInt("cant") ?? TrackTimeTotal;

                // dacp.visualizer
                VisualizerActive = nodes.GetBool("cavs");
                // dacp.visualizerenabled
                VisualizerAvailable = nodes.GetBool("cave");
                // dacp.fullscreen
                FullScreenModeActive = nodes.GetBool("cafs");
                // dacp.fullscreenenabled
                FullScreenModeAvailable = nodes.GetBool("cafe");

                // iTunes Radio
                if (iTunesRadioDatabase != null && iTunesRadioDatabase.ID == CurrentDatabaseID)
                {
                    IsCurrentlyPlayingiTunesRadio = true;
                    CurrentiTunesRadioStationName = nodes.GetString("ceNR");

                    // caks = 1 when the next button is disabled, and 2 when it's enabled
                    IsiTunesRadioNextButtonEnabled = (nodes.GetByte("caks") == 2);

                    // "aelb" indicates whether the star button (iTunes Radio menu) should be enabled, but this only seems to be set to true
                    // when connected via Home Sharing. This parameter is missing when an ad is playing, so use this to determine whether
                    // the menu should be enabled.
                    IsiTunesRadioMenuEnabled = nodes.ContainsKey("aelb");

                    IsiTunesRadioSongFavorited = (nodes.GetByte("aels") == 2);
                }
                else
                {
                    IsCurrentlyPlayingiTunesRadio = false;
                }


                if (IsCurrentlyPlayingiTunesRadio)
                {
                    var caks = nodes.GetByte("caks");
                    IsiTunesRadioNextButtonEnabled = !(caks == 1);
                }

                if (!nodes.ContainsKey("casc") || nodes.GetBool("casc") == true)
                {
                    IsPlayPositionBarEnabled = true;
                }
                else
                {
                    IsPlayPositionBarEnabled = false;
                }

                // Genius Shuffle
                IsCurrentlyPlayingGeniusShuffle = nodes.GetBool("ceGs");
                // There are two other nodes related to Genius Shuffle, "ceGS" and "aeGs" (currently unknown)

                // If the song ID changed, refresh the album art
                if (oldSongID != CurrentItemID)
                {
                    PropertyChanged.RaiseOnUIThread(this, "CurrentAlbumArtURL");
                }

                ThreadUtility.RunOnUIThread(() =>
                {
                    if (PlayState == PlayStates.Playing)
                    {
                        timerTrackTimeUpdate.Start();
                    }
                    else if (PlayState == PlayStates.FastForward || PlayState == PlayStates.Rewind)
                    {
                        BeginRepeatedTrackTimeRequest();
                    }
                });

                var volumeTask     = UpdateCurrentVolumeLevelAsync();
                var userRatingTask = UpdateCurrentSongUserRatingAsync();
                var playQueueTask  = UpdatePlayQueueContentsAsync();

                Task[] tasks = new[] { volumeTask, userRatingTask, playQueueTask };

#if WP7
                await TaskEx.WhenAll(tasks).ConfigureAwait(false);
#else
                await Task.WhenAll(tasks).ConfigureAwait(false);
#endif

                SubmitGetSpeakersRequest();
            }
            catch { return(false); }
            return(true);
        }
 internal void AirPlayMasterVolumeManipulation(int newVolume)
 {
     _currentVolume = newVolume;
     PropertyChanged.RaiseOnUIThread(this, "CurrentVolume", "BindableVolume");
 }