示例#1
0
        public MainWindowVm()
        {
            Logger.Info("Initializing MainWindow View Model");
            TagEditorVm      = new TagEditorVm();
            BpmCalc          = new BpmTapper();
            CurrentSongIndex = 0;
            MainPlayer       = new NAudioPlayer(App.Configuration.MainPlayerDeviceNum, true);
            PreviewPlayer    = new NAudioPlayer(App.Configuration.SecondaryPlayerDeviceNum,
                                                App.Configuration.UpdatePlaycountOnPreview);
            MainPlayer.Volume    = App.Configuration.MainPlayerVolume;
            PreviewPlayer.Volume = App.Configuration.SecondaryPlayerVolume;

            MainPlayer.SongCompletedEvent += (sender, args) =>
            {
                Logger.Info("Song completed; playing next song");
                NextCmd.Execute(null);
            };

            MainPlayer.PropertyChanged    += MainPlayerPropertyChanged;
            PreviewPlayer.PropertyChanged += PreviewPlayerPropertyChanged;

            _columnManager = new ColumnManager();

            BindingOperations.EnableCollectionSynchronization(
                App.SongDb.Songs,
                (App.SongDb.Songs as ICollection).SyncRoot);
            BindingOperations.EnableCollectionSynchronization(
                App.SongDb.GroupCategories,
                (App.SongDb.GroupCategories as ICollection).SyncRoot);

            lock ((App.SongDb.Songs as ICollection).SyncRoot)
            {
                DisplayedSongs = new ListCollectionView(App.SongDb.Songs);
            }

            lock ((App.SongDb.GroupCategories as ICollection).SyncRoot)
            {
                AddGroupDescriptions(0, App.SongDb.GroupCategories);
                App.SongDb.GroupCategories.CollectionChanged +=
                    GroupCategoriesCollectionChanged;
                lock (_displayedSongs)
                {
                    DisplayedSongs.Filter = SongFilter;
                    DisplayedSongs.Refresh();
                }
            }

            lock ((App.SongDb.Columns as ICollection).SyncRoot)
            {
                ((App.SongDb.Columns) as INotifyCollectionChanged).CollectionChanged
                    += OnColumnsChange;
                foreach (var col in App.SongDb.Columns)
                {
                    AddColumn(col);
                }
            }

            SongQueue = new ObservableCollection <Song>();
            Logger.Info("Done initializing MainWindow view model");
        }
        private void Reader_SpeakProgress(object sender, SpeakProgressEventArgs e)
        {
            double p = Math.Round(((e.CharacterPosition * 1.0d) / (SelectedBook.CurrentReadedChapter.ChapterConent.Length * 1.0d)) * 100, 1);

            Progress = (int)p;
            if (p >= 99)
            {
                Console.WriteLine(e.CharacterPosition + "," + SelectedBook.CurrentReadedChapter.ChapterConent.Length);
                Console.WriteLine("自动开始下一章" + SelectedBook.CurrentReadedChapter.NextChapter?.Name);
                NextCmd.Execute(null);
                progress = 0;
            }
        }
示例#3
0
        private void PlaySongAtIndex(int index)
        {
            Logger.Debug("Playing song at index {0}; CurrentSongIndex is {1}",
                         index, CurrentSongIndex);
            Logger.Debug("Stopping current playback, if any");
            MainPlayer.PlaybackState = MediaState.Stop;

            if (index == -1 || index >= SongQueue.Count || index < -2)
            {
                Logger.Debug("index is outside of range, so setting CurrentSongIndex to -1 and returning");
                CurrentSongIndex = -1;
                return;
            }

            if (CurrentSongIndex < 0 || CurrentSongIndex >= SongQueue.Count)
            {
                if (index >= 0)
                {
                    CurrentSongIndex = 0;
                }
                else
                {
                    CurrentSongIndex = SongQueue.Count - 1;
                }
                Logger.Debug("CurrentSongIndex is outside of SongQueue range, so setting it to {0}", CurrentSongIndex);
            }
            else
            {
                Logger.Debug("Setting CurrentSongIndex to our index of {0}", index);
                CurrentSongIndex = index;
            }

            Logger.Debug("Starting playback of our new song");
            MainPlayer.PlaybackState = MediaState.Play;
            if (MainPlayer.PlaybackState != MediaState.Play)
            {
                NextCmd.Execute(null);
            }
        }