예제 #1
0
        /// <summary>
        /// Start the given song playing
        /// </summary>
        /// <param name="song">The song to play</param>
        public override void Play(Song song)
        {
            ITunesSong itSong = song as ITunesSong;

            if (itSong != null && itSong.Track != null)
            {
                itSong.Track.Play();
            }
        }
예제 #2
0
        /// <summary>
        /// Is the given song currently playing
        /// </summary>
        /// <param name="song">The song to check</param>
        /// <returns>Is the given song playing</returns>
        public override bool IsPlaying(Song song)
        {
            ITunesSong itSong = song as ITunesSong;

            if (itSong != null && itSong.Track != null)
            {
                return(ITunes.Instance.IsTrackPlaying(itSong.Track));
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Do the actual work of loading the lyrics from the library
        /// </summary>
        /// <param name="e"></param>
        /// <returns>Ignored</returns>
        protected override object DoWork(DoWorkEventArgs e)
        {
            // How many tracks are there and how many songs should we fetch?
            int maxSongs = ITunes.Instance.AllTracks.Count;

            if (this.MaxSongsToFetch > 0)
            {
                maxSongs = Math.Min(maxSongs, this.MaxSongsToFetch);
            }

            // Load the whole xml file into memory, and then remove the DTD.
            // We remove that so we can read the xml even when not connected to the network
            //string xml = File.ReadAllText(ITunes.Instance.XmlPath);
            //int docTypeStart = xml.IndexOf("<!DOCTYPE");
            //const string endOfDtdMarker = "0.dtd\">";
            //int docTypeEnd = xml.IndexOf(endOfDtdMarker) + endOfDtdMarker.Length;
            //string xml2 = xml.Remove(docTypeStart, docTypeEnd - docTypeStart);

            //XPathDocument doc = new XPathDocument(new StringReader(xml2));
            XmlDocument doc2 = new XmlDocument();

            doc2.XmlResolver = null;
            doc2.Load(ITunes.Instance.XmlPath);
            XPathNavigator nav = doc2.CreateNavigator();

            // Move to plist, then to master library, than tracks, then first track
            nav.MoveToChild("plist", "");
            nav.MoveToChild("dict", "");
            nav.MoveToChild("dict", "");
            bool success = nav.MoveToChild("dict", "");
            Dictionary <string, string> data = new Dictionary <string, string>();

            // Read each song until we have enough or no more
            while (success && this.Songs.Count < maxSongs && this.CanContinueRunning)
            {
                success = nav.MoveToFirstChild();

                // Read each piece of information about the song
                data.Clear();
                while (success)
                {
                    string key = nav.Value;
                    success = nav.MoveToNext();
                    string value = nav.Value;
                    data[key] = value;
                    success   = nav.MoveToNext();
                }

                // Create and add the song if it's not one we want to ignore
                if (data.Count > 0 && !this.KindsToIgnore.Contains(this.GetValue(data, "Kind")))
                {
                    ITunesSong song = new ITunesSong(
                        this.GetValue(data, "Name"),
                        this.GetValue(data, "Artist"),
                        this.GetValue(data, "Album"),
                        this.GetValue(data, "Genre"),
                        this.GetValue(data, "Persistent ID"));
                    this.AddSong(song);
                    this.ReportProgress((this.Songs.Count * 100) / maxSongs);
                }
                success = nav.MoveToParent();
                success = nav.MoveToNext("dict", "");
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Do the actual work of loading the lyrics from the library
        /// </summary>
        /// <param name="e"></param>
        /// <returns>Ignored</returns>
        protected override object DoWork(DoWorkEventArgs e)
        {
            // How many tracks are there and how many songs should we fetch?
            int maxSongs = ITunes.Instance.AllTracks.Count;
            if (this.MaxSongsToFetch > 0)
                maxSongs = Math.Min(maxSongs, this.MaxSongsToFetch);

            // Load the whole xml file into memory, and then remove the DTD.
            // We remove that so we can read the xml even when not connected to the network
            //string xml = File.ReadAllText(ITunes.Instance.XmlPath);
            //int docTypeStart = xml.IndexOf("<!DOCTYPE");
            //const string endOfDtdMarker = "0.dtd\">";
            //int docTypeEnd = xml.IndexOf(endOfDtdMarker) + endOfDtdMarker.Length;
            //string xml2 = xml.Remove(docTypeStart, docTypeEnd - docTypeStart);

            //XPathDocument doc = new XPathDocument(new StringReader(xml2));
            XmlDocument doc2 = new XmlDocument();
            doc2.XmlResolver = null;
            doc2.Load(ITunes.Instance.XmlPath);
            XPathNavigator nav = doc2.CreateNavigator();

            // Move to plist, then to master library, than tracks, then first track
            nav.MoveToChild("plist", "");
            nav.MoveToChild("dict", "");
            nav.MoveToChild("dict", "");
            bool success = nav.MoveToChild("dict", "");
            Dictionary<string, string> data = new Dictionary<string, string>();

            // Read each song until we have enough or no more
            while (success && this.Songs.Count < maxSongs && this.CanContinueRunning) {
                success = nav.MoveToFirstChild();

                // Read each piece of information about the song
                data.Clear();
                while (success) {
                    string key = nav.Value;
                    success = nav.MoveToNext();
                    string value = nav.Value;
                    data[key] = value;
                    success = nav.MoveToNext();
                }

                // Create and add the song if it's not one we want to ignore
                if (data.Count > 0 && !this.KindsToIgnore.Contains(this.GetValue(data, "Kind"))) {
                    ITunesSong song = new ITunesSong(
                        this.GetValue(data, "Name"),
                        this.GetValue(data, "Artist"),
                        this.GetValue(data, "Album"),
                        this.GetValue(data, "Genre"),
                        this.GetValue(data, "Persistent ID"));
                    this.AddSong(song);
                    this.ReportProgress((this.Songs.Count * 100) / maxSongs);
                }
                success = nav.MoveToParent();
                success = nav.MoveToNext("dict", "");
            }

            return true;
        }