Пример #1
0
        /// <summary>
        ///   Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(iTunesService iTunesModel)
        {
            iTunesService = iTunesModel;
            if (IsInDesignMode)
            {
                var blendPlaylist = new iTunesPlaylist(3, "Wicked Awesome Playlist");
                blendPlaylist.Tracks.Add(new Track("Dancing Queen", 1, 2));
                blendPlaylist.Tracks.Add(new Track("The Humpty Dance", 2, 3));
                blendPlaylist.Tracks.Add(new Track("Birdhouse In Your Soul", 3, 4));

                Playlists = new ObservableCollection<iTunesPlaylist>
                    {
                        blendPlaylist,
                        new iTunesPlaylist(1, "Test"),
                        new iTunesPlaylist(2, "Test2")
                    };

                _currentTrack = "Blister in the Sun";
            }
            else
            {
                Playlists = new ObservableCollection<iTunesPlaylist>();
                SynchronizePlaylists();
                _currentTrack = iTunesService.CurrentStatus.CurrentTrack;

                iTunesService.PropertyChanged += TunesServicePropertyChanged;

                NextTrackCommand = new RelayCommand<int>(tracks => iTunesService.NextTrack(tracks));
                PreviousTrackCommand = new RelayCommand<int>(tracks => iTunesService.PreviousTrack(tracks));
                PlayPauseCommand = new RelayCommand(() => iTunesService.PlayPause());
                PlayTrackCommand = new RelayCommand(() =>
                    {
                        if (SelectedPlayList != null)
                        {
                            if (SelectedPlayList.SelectedTrack != null)
                            {
                                iTunesService.PlaySelectedTrack(SelectedPlayList, SelectedPlayList.SelectedTrack);
                            }
                        }
                    });
            }
        }
Пример #2
0
        private List<iTunesPlaylist> ListPlaylists()
        {
            var result = new List<iTunesPlaylist>();

            IITPlaylistCollection playlists = iTunes.LibrarySource.Playlists;
            for (int n = 1; n <= playlists.Count; n++)
            {
                var playlist = new iTunesPlaylist(playlists[n].playlistID, playlists[n].Name);

                if (playlist.Name != "Library")
                {
                    for (int t = 1; t < playlists[n].Tracks.Count; t++)
                    {
                        int low;
                        int high;
                        object iObject = playlists[n].Tracks[t];
                        iTunes.GetITObjectPersistentIDs(ref iObject, out high, out low);

                        playlist.Tracks.Add(new Track(playlists[n].Tracks[t].Name, low, high));
                    }

                    result.Add(playlist);
                }
            }

            return result;
        }