コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        private void Tick(object sender, ElapsedEventArgs e)
        {
            if (_hotPlaylist)
            {
                PlaylistSaver.SaveAll();
                _hotPlaylist = false;
            }

            if (!_isSongPlaying)
            {
                return;
            }
            if (manager.Finished)
            {
                if (_currentSong >= _history.Count - 1)
                {
                    _isSongPlaying = false;
                    Dispatcher.BeginInvoke((Action) delegate
                    {
                        Title = "Music Time";
                    });
                    return;
                }
                _currentSong++;
                TotalTimeLabel.Dispatcher.BeginInvoke((Action) delegate
                {
                    PlaySong(_history[_currentSong]);
                });
            }
            TotalTimeLabel.Dispatcher.BeginInvoke((Action) delegate
            {
                Title = "Music Time | " + manager.StatusString;
                ProgresSlider.Maximum    = (int)manager.CurrentMedia.duration;
                TotalTimeLabel.Content   = manager.CurrentMedia.durationString;
                CurrentTimeLabel.Content = manager.CurrentTimeString;
                double percentage        = (manager.CurrentTime / manager.CurrentMedia.duration);
                ProgresSlider.Value      = (int)(percentage * ProgresSlider.Maximum);
                if (_currentSong == -1 || _currentSong == _history.Count - 1)
                {
                    NextButton.IsEnabled = false;
                    NextRect.Fill        = Brushes.Gray;
                }
                else
                {
                    NextButton.IsEnabled = true;
                    NextRect.Fill        = ThemeManager.DetectAppStyle(Application.Current).Item1 == ThemeManager.GetAppTheme("BaseDark") ? Brushes.White : Brushes.Black;
                }

                if ((_currentSong == -1 || _currentSong == 0) && percentage < 0.05d)
                {
                    PrevButton.IsEnabled = false;
                    PrevRect.Fill        = Brushes.Gray;
                }
                else
                {
                    PrevButton.IsEnabled = true;
                    PrevRect.Fill        = ThemeManager.DetectAppStyle(Application.Current).Item1 == ThemeManager.GetAppTheme("BaseDark") ? Brushes.White : Brushes.Black;
                }
            });
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            //Create new playlist
            Playlist playlist = new Playlist();

            playlist.Name  = "New Playlist";
            playlist.Songs = new List <SavedSong>();
            PlaylistSaver.Data.Add(playlist);
            PlaylistSaver.SaveAll();

            var mi = new MenuItem();

            mi.Header = "Add to " + playlist.Name;
            mi.Click += MenuItem_OnClick;
            SearchContextMenu.Items.Add(mi);

            var btn = CreatePlaylistButton();

            btn.Content = playlist.Name;
            btn.Click  += (s, _) =>
            {
                _shownPlaylistButton = (Button)s;
                DisplayPlaylist(playlist);
            };

            _mainPlaylistData.Add(playlist, new PlaylistData()
            {
                AssociatedButton      = btn,
                AssociatedContextItem = mi,
            });

            _shownPlaylist       = playlist;
            _shownPlaylistButton = btn;
            PlaylistStackPanel.Children.Insert(PlaylistStackPanel.Children.Count - 1, btn);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        public MainWindow()
        {
            InitializeComponent();
            manager  = new AudioManager();
            _history = new List <KnownSongInfo>();
            PlaylistSaver.LoadPlaylists();
            _settings = Settings.Load();
            Timer t = new Timer(1000);

            t.Elapsed += Tick;
            t.Start();
            InitializePlaylists();

            ThemeToggleSwitch.IsChecked = _settings.BaseTheme == "BaseLight";
            ComboBoxItem ourItem = new ComboBoxItem();

            for (int i = 0; i < SettingsAccentComboBox.Items.Count; i++)
            {
                if (((ComboBoxItem)SettingsAccentComboBox.Items[i]).Content.ToString() == _settings.Accent)
                {
                    ourItem = (ComboBoxItem)SettingsAccentComboBox.Items[i];
                }
            }
            SettingsAccentComboBox.SelectedIndex = SettingsAccentComboBox.Items.IndexOf(ourItem);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        private void DeletePlaylistButton_Click(object sender, RoutedEventArgs e)
        {
            PlaylistStackPanel.Children.Remove(_shownPlaylistButton);
            SearchContextMenu.Items.Remove(_mainPlaylistData[_shownPlaylist].AssociatedContextItem);

            PlaylistSaver.Data.Remove(_shownPlaylist);
            PlaylistSaver.SaveAll();
            MainTabControl.SelectedItem = SearchTabItem;
            _shownPlaylist       = null;
            _shownPlaylistButton = null;
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        private void PlaylistContextMenu_OnClick(object sender, RoutedEventArgs e)
        {
            if (_shownPlaylist == null)
            {
                return;
            }
            var menuItem = (MenuItem)sender;

            var contextMenu = (ContextMenu)menuItem.Parent;
            var row         = (DataGrid)contextMenu.PlacementTarget;
            var item        = (KnownSongInfo)row.SelectedCells[0].Item;

            var data = PlaylistSaver.Data.First(p => p.Equals(_shownPlaylist));
            var song = data.Songs.First(s => s.Uri == item.GetSong().Uri);

            data.Songs.Remove(song);
            PlaylistSaver.SaveAll();
            DisplayPlaylist(data);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: Guad/MusicTimeGUI
        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            // Add to playlist
            var menuItem = (MenuItem)sender;

            var contextMenu = (ContextMenu)menuItem.Parent;
            var row         = (DataGrid)contextMenu.PlacementTarget;
            var item        = (KnownSongInfo)row.SelectedCells[0].Item;
            var playlist    = _mainPlaylistData.FirstOrDefault(p => Equals(p.Value.AssociatedContextItem, menuItem)).Key;

            if (playlist == null)
            {
                MessageBox.Show("Error while looking for playlist.");
                return;
            }

            var songData = new SavedSong()
            {
                Artist = item.Artist,
                Name   = item.Name,
                Uri    = item.GetSong().Uri,
            };


            var data = PlaylistSaver.Data.First(p => p.Equals(playlist));

            if (data.Songs == null)
            {
                data.Songs = new List <SavedSong> {
                    songData
                }
            }
            ;
            else
            {
                data.Songs.Add(songData);
            }
            PlaylistSaver.SaveAll();
        }