Beispiel #1
0
 public void RecordTrackUpdated(MusicTrack track)
 {
     if (TrackUpdate != null)
     {
         TrackUpdate(this, track);
     }
 }
Beispiel #2
0
        public static MusicTrack Parse(string xml)
        {
            var track = new MusicTrack();

            var element = XElement.Parse(xml);

            var classType = SetValueIfNodeNotNull(element, "class", "urn:schemas-upnp-org:metadata-1-0/upnp/");

            if (classType != "object.item.audioItem.musicTrack")
            {
                return(null);
            }

            track.Title   = SetValueIfNodeNotNull(element, "title", "http://purl.org/dc/elements/1.1/");
            track.Creator = SetValueIfNodeNotNull(element, "creator", "http://purl.org/dc/elements/1.1/");

            var resourceUri = SetValueIfNodeNotNull(element, "res", "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/");

            if (!string.IsNullOrEmpty(resourceUri))
            {
                track.ResourceUri = new Uri(resourceUri);
            }


            track.Album = new Album
            {
                Name = SetValueIfNodeNotNull(element, "album", "urn:schemas-upnp-org:metadata-1-0/upnp/")
            };

            var albumArtUri = SetValueIfNodeNotNull(element, "albumArtURI", "urn:schemas-upnp-org:metadata-1-0/upnp/");

            if (!string.IsNullOrEmpty(albumArtUri))
            {
                track.Album.ImageUrl = new Uri(albumArtUri);
            }

            return(track);
        }
Beispiel #3
0
        public void RecordStateVariableChange(string xml)
        {
            var doc = XElement.Parse(xml);

            var currentTrackMetaDataNode = doc
                                           .Descendants(XName.Get("CurrentTrackMetaData", "urn:schemas-upnp-org:metadata-1-0/AVT/"))
                                           .SingleOrDefault(n => !String.IsNullOrEmpty(n.Attribute("val").Value));

            var transportStateNode = doc
                                     .Descendants(XName.Get("TransportState", "urn:schemas-upnp-org:metadata-1-0/AVT/"))
                                     .SingleOrDefault(n => n.HasAttributes);

            var masterMuteNode = doc
                                 .Descendants(XName.Get("Mute", "urn:schemas-upnp-org:metadata-1-0/RCS/"))
                                 .SingleOrDefault(n => n.Attribute("channel").Value == "Master");


            var masterVolumeNode = doc
                                   .Descendants(XName.Get("Volume", "urn:schemas-upnp-org:metadata-1-0/RCS/"))
                                   .SingleOrDefault(n => n.Attribute("channel").Value == "Master");

            if (currentTrackMetaDataNode != null)
            {
                var xmlString = currentTrackMetaDataNode.Attribute("val").Value;
                var track     = MusicTrack.Parse(xmlString);

                if (track != null)
                {
                    RecordTrackUpdated(track);
                }
            }


            if (transportStateNode != null)
            {
                var transportState = transportStateNode.Attribute("val").Value;
                switch (transportState)
                {
                case "STOPPED":
                case "PAUSED_PLAYBACK":
                    RecordStopped();
                    break;

                case "TRANSITIONING":
                    RecordTransitioning();
                    break;

                case "PLAYING":
                    RecordPlaying();
                    break;
                }
            }

            if (masterVolumeNode != null)
            {
                var volume = int.Parse(masterVolumeNode.Attribute("val").Value);
                RecordVolumeChange(volume);
            }

            if (masterMuteNode != null)
            {
                var muted = Convert.ToBoolean(int.Parse(masterMuteNode.Attribute("val").Value));
                RecordMuteChange(muted);
            }
        }