Exemplo n.º 1
0
        private void InitializePlaylistContent()
        {
            TracksViewModel     tracksVM     = new TracksViewModel(PlaylistCollection.GetPlaylist(Properties.Settings.Default.LastSelectedPlaylistGUID));
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                throw new Exception("Failed to cast object");
            }

            lv_Playlist.DataContext = tracksVM;
            if (trackListsVM.CurrentPlaylist != null)
            {
                lv_Playlist.ItemsSource = trackListsVM.CurrentPlaylist.Soundtracks as IEnumerable <TrackInfo>;
                tracksVM.UpdateSoundtracks(trackListsVM.CurrentPlaylist);
            }
            else
            {
                lv_Playlist.ItemsSource = null;
            }

            // Bind event for updating content of view-model of lb_PlaylistMenu
            tracksVM.PlaylistIsUpdatedEvent += (lb_PlaylistMenu.DataContext as TrackListsViewModel).UpdateTrackList;
            // Update trackQueue
            tracksVM.PlaylistIsUpdatedEvent += OnPlaylistIsUpdated;
        }
Exemplo n.º 2
0
        // TODO: add a parameter: get prev/next
        private TrackInfo GetTrack(MusicPlayer player, Guid listGUID,
                                   int selectedTrackIndex = -1, PlaybackMode mode = PlaybackMode.None, bool selectNext = true)
        {
            if (lb_PlaylistMenu.Items.Count == 0)
            {
                throw new EmptyPlaylistException("No tracklist is avalible");
            }

            try
            {
                // If no playlist is selected (user click btn_StartPlayback to play music)
                TracksViewModel tracksVM = lv_Playlist.DataContext as TracksViewModel;
                listGUID = (listGUID == Guid.Empty) ? tracksVM.TracklistGUID : listGUID;

                if (mode == PlaybackMode.None)
                {
                    throw new Exception("Invalid playback mode");
                }

                return(selectNext ? player.GetTrack(listGUID, selectedTrackIndex, mode) : player.GetPrevTrack(listGUID, selectedTrackIndex, mode));
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 3
0
        private void txtEditBox_LostFocus(object sender, RoutedEventArgs e)
        {
            ListBoxItem lbi    = ((TextBox)sender).TemplatedParent as ListBoxItem;
            string      result = SwitchEditingMode(lbi, false);

            Guid targetGUID = (lb_PlaylistMenu.SelectedItem as Playlist).GUID;

            if (result != oriPlaylistName)
            {
                TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;
                trackListsVM.UpdatePlaylistName(targetGUID, result);
                TracksViewModel tracksVM = lv_Playlist.DataContext as TracksViewModel;
                tracksVM.UpdatePlaylistInfo(targetGUID, result);
                lb_PlaylistMenu.UpdateLayout();
            }

            oriPlaylistName = "";   // Reset
        }
Exemplo n.º 4
0
        private void lv_Playlist_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete && lv_Playlist.SelectedItems.Count != 0)
            {
                TracksViewModel  tracksVM = lv_Playlist.DataContext as TracksViewModel;
                List <TrackInfo> tracks   = lv_Playlist.SelectedItems.OfType <TrackInfo>().ToList();

                // Stop player if selected track is playing
                foreach (TrackInfo track in lv_Playlist.SelectedItems)
                {
                    if (track.TrackStatus == TrackStatus.Playing)
                    {
                        StopPlayerRequestEvent();
                    }
                }

                tracksVM.RemoveTracks();
            }
        }
Exemplo n.º 5
0
        public void SetTrackStatus(TrackStatusEventArgs e)
        {
            // Check
            if (e == null || e.Index == -1)
            {
                return;
            }

            TracksViewModel     tracksVM     = lv_Playlist.DataContext as TracksViewModel;
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            // TODO: try to rewrite this
            Playlist pl = trackListsVM.TrackLists.First(x => x.GUID == e.OwnerListGUID);

            pl.Soundtracks.Find(x => x.GUID == e.Track.GUID).TrackStatus = e.Track.TrackStatus;

            if (pl.GUID == e.OwnerListGUID)
            {
                tracksVM.UpdateTrackStatus(e);
            }
        }
Exemplo n.º 6
0
        private void RefreshPlaylistContent()
        {
            TracksViewModel tracksVM = lv_Playlist.DataContext as TracksViewModel;

            if (tracksVM == null)
            {
                return;
            }
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                return;
            }

            Playlist pl = trackListsVM.CurrentPlaylist;

            if (pl == null)
            {
                lv_Playlist.Visibility = Visibility.Hidden;
                return;
            }

            tracksVM.UpdatePlaylistInfo(pl);
            tracksVM.UpdateSoundtracks(pl);
            lv_Playlist.ItemsSource = tracksVM.Soundtracks as IEnumerable <TrackInfo>;

            // Update info
            Properties.Settings.Default.LastSelectedPlaylistGUID = pl.GUID;
            Properties.Settings.Default.Save();

            // Show playing track
            if (lb_PlaylistMenu.SelectedItem != null && ListContentIsRefreshedEvent != null)
            {
                if (Properties.Settings.Default.TaskPlaylistGUID == pl.GUID)
                {
                    tracksVM.UpdateTrackStatus(ListContentIsRefreshedEvent());
                }
            }
        }