/// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            if (ViewModelBase.IsInDesignModeStatic)
            {
                // Create design time services and viewmodels
                _main = new MainViewModel(null);
            }
            else
            {
                // Create run time services and view models
                //var model = new iTunesService("http://192.168.1.12:8081/");
                var model = new iTunesService("http://localhost:8080/");

                _main = new MainViewModel(model);
            }
        }
Exemple #2
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);
                            }
                        }
                    });
            }
        }