public async Task Move(int updown) { _timer.Stop(); // Calculate index position var sequence = _book.Sequence.Where( w => w.Filename == _playerInfo.CurrentFilename && w.TCIn <= _playerInfo.Position.CurrentTC && w.TCOut > _playerInfo.Position.CurrentTC).FirstOrDefault(); if (sequence != null) { _playerInfo.Position.CurrentIndex = _book.Sequence.IndexOf(sequence); } var index = _playerInfo.Position.CurrentIndex; do { index += updown; } while (index > 0 && index < _book.Sequence.Count && _book.Sequence[index].Level > _playerInfo.Position.NavigationLevel); // adjust bounds if (index < 0) { index = 0; return; } else if (index > _book.Sequence.Count - 1) { index = _book.Sequence.Count - 1; return; } else { _playerInfo.Position.CurrentIndex = index; _playerInfo.Position.CurrentSOM = _book.Sequence[index].SOM; _playerInfo.Position.CurrentTC = _book.Sequence[index].TCIn; _playerInfo.Position.CurrentTitle = _book.Sequence[index].Title; ChapterUpdate?.Invoke(_book.Title, _playerInfo.Position.CurrentTitle); TimeCodeUpdate?.Invoke( new TimeSpan() .Add(TimeSpan.FromSeconds(_playerInfo.Position.CurrentSOM)) .Add(TimeSpan.FromSeconds(_playerInfo.Position.CurrentTC)) ); } await CrossMediaManager.Current.Pause(); if (_book.Sequence[index].Filename != _playerInfo.CurrentFilename) { _playerInfo.CurrentFilename = $"{_book.Sequence[index].Filename}"; _fileChanged = true; } _timer.Start(); SaveStatus(); }
public async void LoadBook(DaisyBook book) { // Save status of a previous book loaded if (_playerInfo != null) { SaveStatus(); } _book = book; _playerInfo = new PlayerInfo { Position = new SeekInfo { CurrentIndex = 0, NavigationLevel = DaisyBook.NAV_LEVEL_SECTION }, }; _playerInfo.CurrentFilename = $"{_book.Sequence[_playerInfo.Position.CurrentIndex].Filename}"; LoadStatus(); ChapterUpdate?.Invoke(_book.Title, _book.Sequence[0].Title); await CrossMediaManager.Current.Play( new MediaItem { Title = _playerInfo.Position.CurrentTitle, MediaLocation = MediaLocation.FileSystem, MediaUri = $"{Session.Instance.GetDataDir()}/{_book.Id}/{_playerInfo.CurrentFilename}" } ); _seekToCurrentTC = true; }
private async Task <bool> LoadNextFile() { var currentSeq = _book.Sequence[_playerInfo.Position.CurrentIndex]; string newFile = null; int newIndex = 0; for (var i = _playerInfo.Position.CurrentIndex; i < _book.Sequence.Count; i++) { if (_book.Sequence[i].Filename != currentSeq.Filename) { newFile = _book.Sequence[i].Filename; newIndex = i; break; } } if (newFile != null) { _playerInfo.CurrentFilename = $"{newFile}"; _playerInfo.Position.CurrentIndex = newIndex; _playerInfo.Position.CurrentSOM = _book.Sequence[newIndex].SOM; _playerInfo.Position.CurrentTC = 0; _playerInfo.Position.CurrentTitle = _book.Sequence[newIndex].Title; ChapterUpdate?.Invoke(_book.Title, _playerInfo.Position.CurrentTitle); await CrossMediaManager.Current.Play( new MediaItem { Title = _playerInfo.Position.CurrentTitle, MediaLocation = MediaLocation.FileSystem, MediaType = MediaType.Audio, MediaUri = $"{Session.Instance.GetDataDir()}/{_book.Id}/{_playerInfo.CurrentFilename}" } ); SaveStatus(); return(true); } else { return(false); } }