internal void SetSingleActiveSpeaker(AirPlaySpeaker speaker)
        {
            string url = "/ctrl-int/1/setspeakers"
                         + "?speaker-id=0x" + speaker.ID.ToString("x")
                         + "&session-id=" + SessionID;

            SubmitHTTPRequest(url, new HTTPResponseHandler(ProcessSetActiveSpeakersResponse), true, r => r.ExceptionHandlerDelegate = new HTTPExceptionHandler(HandleSetActiveSpeakersException));
        }
 public void AirPlaySpeakerManipulationStopped(AirPlaySpeaker speaker)
 {
     if (!speaker.WaitingForVolumeResponse)
     {
         SubmitGetSpeakersRequest();
     }
     else
     {
         needToGetSpeakers = true;
     }
 }
        public void AirPlaySpeakerManipulationStarted(AirPlaySpeaker speaker)
        {
            needToGetSpeakers = false;
            AirPlaySpeaker otherSpeaker;

            lock (Speakers)
            {
                otherSpeaker = (from s in Speakers
                                where s != speaker && s.Active
                                orderby s.BindableVolume descending
                                select s).FirstOrDefault();
            }

            if (otherSpeaker != null)
            {
                AirPlayVolumeSwitchPoint = otherSpeaker.BindableVolume;
            }
            else
            {
                AirPlayVolumeSwitchPoint = 0;
            }
        }
        protected void ProcessGetSpeakersResponse(HTTPRequestInfo requestInfo)
        {
            List <UInt64> foundSpeakerIDs = new List <UInt64>();

            string name;
            UInt64 id;
            bool   hasPassword;
            bool   hasVideo;
            bool   active;
            int    volume;

            foreach (var kvp in requestInfo.ResponseNodes)
            {
                if (kvp.Key == "mdcl")
                {
                    name        = string.Empty;
                    id          = 0;
                    hasPassword = false;
                    hasVideo    = false;
                    active      = false;
                    volume      = 0;

                    var speakerNodes = DACPUtility.GetResponseNodes(kvp.Value);

                    foreach (var speakerKvp in speakerNodes)
                    {
                        switch (speakerKvp.Key)
                        {
                        case "minm":     // Speaker name
                            name = speakerKvp.Value.GetStringValue();
                            break;

                        case "msma":     // Speaker ID
                            id = (UInt64)speakerKvp.Value.GetInt64Value();
                            break;

                        case "cahp":     // Has Password
                            hasPassword = (speakerKvp.Value[0] > 0);
                            break;

                        case "caiv":     // Has Video
                            hasVideo = true;
                            break;

                        case "caia":     // Speaker active
                            active = (speakerKvp.Value[0] > 0);
                            break;

                        case "cmvo":     // Speaker volume
                            volume = speakerKvp.Value.GetInt32Value();
                            break;

                        default:
                            break;
                        }
                    }

                    if (foundSpeakerIDs.Contains(id))
                    {
                        continue;
                    }

                    foundSpeakerIDs.Add(id);

                    AirPlaySpeaker speaker;

                    lock (Speakers)
                    {
                        speaker = Speakers.FirstOrDefault(s => s.ID == id);
                        if (speaker == null)
                        {
                            speaker          = new AirPlaySpeaker(this, id);
                            speaker.HasVideo = (hasVideo || id == 0);
                            ThreadUtility.RunOnUIThread(() => Speakers.Add(speaker));
                        }
                    }

                    speaker.HasPassword = hasPassword;
                    speaker.Name        = name;
                    speaker.Active      = active;
                    speaker.Volume      = volume;
                    speaker.WaitingForActiveResponse = false;
                }
            }

            lock (Speakers)
            {
                // Handle speakers that are no longer available
                // Need to call ToList() so the source collection doesn't change during enumeration
                var removedSpeakers = Speakers.Where(s => !foundSpeakerIDs.Contains(s.ID)).ToList();
                foreach (AirPlaySpeaker removedSpeaker in removedSpeakers)
                {
                    ThreadUtility.RunOnUIThread(() => Speakers.Remove(removedSpeaker));
                }
            }

            SendAirPlaySpeakerUpdate();
            gettingSpeakers = false;
        }