Пример #1
0
        // GET: /Spotify/GetPlayingInfo
        public ContentResult GetPlayingInfo()
        {
            SpotifyData.Track currentTrack = Spotify.GetCurrentTrack();
            IEnumerable <SpotifyData.Track> queuedTracks = Spotify.GetQueuedTracks();

            if (currentTrack == null)
            {
                XElement stoppedInfo = new XElement("Track",
                                                    new XAttribute("id", ""),
                                                    new XAttribute("name", ""),
                                                    new XAttribute("album", ""),
                                                    new XAttribute("albumid", ""),
                                                    new XAttribute("albumArtist", ""),
                                                    new XAttribute("trackArtists", ""),
                                                    new XAttribute("duration", 0),
                                                    new XAttribute("position", 0),
                                                    new XAttribute("status", "Stopped"),
                                                    new XAttribute("postionDisplay", ""),
                                                    new XAttribute("indexDisplay", ""));

                return(this.Content(stoppedInfo.ToString(), @"text/xml", Encoding.UTF8));
            }

            int pos        = Spotify.GetPosition();
            int trackCount = 0;
            int trackIndex = 0;

            foreach (SpotifyData.Track track in queuedTracks)
            {
                trackCount++;
                if (track.Id == currentTrack.Id)
                {
                    trackIndex = trackCount;
                }
            }

            int playStatus = Spotify.GetPlaying();

            XElement info = new XElement("Track",
                                         new XAttribute("id", currentTrack.Id),
                                         new XAttribute("name", currentTrack.Name),
                                         new XAttribute("album", currentTrack.AlbumName),
                                         new XAttribute("albumid", currentTrack.AlbumId),
                                         new XAttribute("albumArtist", currentTrack.AlbumArtistName),
                                         new XAttribute("trackArtists", currentTrack.TrackArtistNames),
                                         new XAttribute("duration", currentTrack.Duration),
                                         new XAttribute("position", pos),
                                         new XAttribute("status", playStatus == -1 ? "Stolen" : playStatus == 0 ? "Paused" : "Playing"),
                                         new XAttribute("postionDisplay", Spotify.FormatDuration(pos) + "/" + Spotify.FormatDuration(currentTrack.Duration)),
                                         new XAttribute("indexDisplay", trackIndex + "/" + trackCount));

            return(this.Content(info.ToString(), @"text/xml", Encoding.UTF8));
        }