Esempio n. 1
0
        private void OnFileDurationChanged(double seconds)
        {
            IsPaused = false;

            if (_currentlyPlayedFile is null)
            {
                return;
            }

            CurrentPlayedSeconds = seconds;

            var elapsed = TimeSpan.FromSeconds(seconds)
                          .ToString(FileFormatConstants.FullElapsedTimeFormat);
            var total = TimeSpan.FromSeconds(_currentlyPlayedFile.TotalSeconds)
                        .ToString(FileFormatConstants.FullElapsedTimeFormat);

            if (_currentlyPlayedFile.IsUrlFile && _currentlyPlayedFile.TotalSeconds <= 0)
            {
                ElapsedTimeString = $"{elapsed}";
            }
            else
            {
                ElapsedTimeString = $"{elapsed} / {total}";
            }

            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == _currentlyPlayedFile.PlayListId);

            playlist?.UpdatePlayedTime();
        }
Esempio n. 2
0
        public FileLoadedResponseDto GetCurrentFileLoadedForMediaWebSocket()
        {
            if (_currentlyPlayedFile == null)
            {
                return(null);
            }

            var response = new FileLoadedResponseDto
            {
                Id             = _currentlyPlayedFile.Id,
                Duration       = _currentlyPlayedFile.TotalSeconds,
                Filename       = _currentlyPlayedFile.Filename,
                LoopFile       = _currentlyPlayedFile.Loop,
                CurrentSeconds = CurrentPlayedSeconds,
                IsPaused       = IsPaused,
                IsMuted        = IsMuted,
                VolumeLevel    = VolumeLevel,
                ThumbnailUrl   = CurrentFileThumbnail
            };

            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == _currentlyPlayedFile.PlayListId);

            response.PlayListId      = playlist?.Id ?? 0;
            response.PlayListName    = playlist?.Name ?? "N/A";
            response.LoopPlayList    = playlist?.Loop ?? false;
            response.ShufflePlayList = playlist?.Shuffle ?? false;
            return(response);
        }
Esempio n. 3
0
        private async Task OnFwRenamed(string oldPath, string newPath, bool isAFolder)
        {
            var files = PlayLists
                        .SelectMany(f => f.Items)
                        .Where(f => isAFolder ? f.Path.StartsWith(oldPath) : f.Path == oldPath)
                        .ToList();

            foreach (var file in files)
            {
                var playlist = PlayLists.FirstOrDefault(f => f.Id == file.PlayListId);
                if (playlist == null)
                {
                    continue;
                }

                if (isAFolder)
                {
                    //Here I'm not sure how to retain the order
                    await playlist.RemoveFilesThatStartsWith(oldPath);

                    await playlist.OnFolderAddedCommand.ExecuteAsync(new[] { newPath });
                }
                else
                {
                    await playlist.OnFilesAddedCommand.ExecuteAsync(new[] { newPath });

                    playlist.ExchangeLastFilePosition(file.Id);
                    await playlist.RemoveFile(file.Id);
                }
                _appWebServer?.OnPlayListChanged(playlist.Id);
            }
        }
Esempio n. 4
0
        private void OnFileEndReached()
        {
            Logger.LogInformation($"{nameof(OnFileEndReached)}: End reached for file = {_currentlyPlayedFile?.Path}");

            SetCurrentlyPlayingInfo(null, false);

            IsPaused = false;

            if (_currentlyPlayedFile != null)
            {
                var playlist = PlayLists.FirstOrDefault(pl => pl.Id == _currentlyPlayedFile.PlayListId);
                playlist?.UpdatePlayedTime();
            }

            if (_currentlyPlayedFile?.Loop == true)
            {
                Logger.LogInformation($"{nameof(OnFileEndReached)}: Looping file = {_currentlyPlayedFile?.Path}");
                _currentlyPlayedFile.PlayedPercentage = 0;
                _currentlyPlayedFile.PlayCommand.Execute();
                return;
            }

            if (_settingsService.PlayNextFileAutomatically)
            {
                Logger.LogInformation($"{nameof(OnFileEndReached)}: Play next file is enabled. Playing the next file...");
                GoTo(true, true);
            }
            else
            {
                Logger.LogInformation($"{nameof(OnFileEndReached)}: Play next file is disabled. Next file won't be played, playback will stop now");
                StopPlayBackCommand.Execute();
            }
        }
Esempio n. 5
0
        public Task RenamePlayList(long id, string newName)
        {
            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == id);

            if (playlist != null)
            {
                return(playlist.SavePlayList(newName));
            }
            Logger.LogWarning($"{nameof(RenamePlayList)}: Cant rename playlistId = {id} because it doesnt exists");
            return(ShowSnackbarMsg(GetText("PlayListDoesntExist")));
        }
Esempio n. 6
0
        public Task DeleteFile(long id, long playListId)
        {
            var playList = PlayLists.FirstOrDefault(pl => pl.Id == playListId);

            if (playList != null)
            {
                return(playList.RemoveFile(id));
            }
            Logger.LogWarning($"{nameof(DeleteFile)}: Couldnt delete fileId = {id} because playlistId = {playListId} doesnt exists");
            return(ShowSnackbarMsg(GetText("PlayListDoesntExist")));
        }
Esempio n. 7
0
        public Task DeletePlayList(long id)
        {
            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == id);

            if (playlist != null)
            {
                _beforeDeletingPlayList.Raise(playlist);
                return(Task.CompletedTask);
            }
            Logger.LogWarning($"{nameof(DeletePlayList)}: Cant delete playlistId = {id} because it doesnt exists");
            return(ShowSnackbarMsg(GetText("PlayListDoesntExist")));
        }
Esempio n. 8
0
        public void SetPlayListOptions(long id, bool loop, bool shuffle)
        {
            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == id);

            if (playlist == null)
            {
                Logger.LogWarning($"{nameof(SetPlayListOptions)}: PlaylistId = {id} doesnt exists");
                _appWebServer.OnServerMsg?.Invoke(GetText("PlayListDoesntExist"));
                return;
            }

            playlist.Loop    = loop;
            playlist.Shuffle = shuffle;
        }
Esempio n. 9
0
        private async Task OnFwChanged(string path, bool isAFolder)
        {
            var files = PlayLists
                        .SelectMany(f => f.Items)
                        .Where(f => isAFolder ? f.Path.StartsWith(path) : f.Path == path)
                        .ToList();

            foreach (var file in files)
            {
                var playlist = PlayLists.FirstOrDefault(f => f.Id == file.PlayListId);
                if (playlist == null)
                {
                    continue;
                }

                await playlist.SetFileInfo(file.Id, _setDurationTokenSource.Token);

                _appWebServer?.OnFileChanged(playlist.Id);
            }
        }
Esempio n. 10
0
        public PlayListItemResponseDto GetPlayListForMediaWebSocket(long playlistId)
        {
            var playlist = PlayLists.FirstOrDefault(pl => pl.Id == playlistId);

            if (playlist == null)
            {
                return(null);
            }

            return(new PlayListItemResponseDto
            {
                Id = playlist.Id,
                Loop = playlist.Loop,
                Name = playlist.Name,
                NumberOfFiles = playlist.Items.Count,
                Position = playlist.Position,
                Shuffle = playlist.Shuffle,
                TotalDuration = playlist.TotalDuration,
                Files = _mapper.Map <List <FileItemResponseDto> >(playlist.Items)
            });
        }
Esempio n. 11
0
        public Task SetFileLoop(long id, long playlistId, bool loop)
        {
            var pl = PlayLists.FirstOrDefault(pl => pl.Id == playlistId);

            if (pl == null)
            {
                Logger.LogWarning($"{nameof(SetFileLoop)}: Couldnt update fileId = {id} because playlistId = {playlistId} doesnt exists");
                return(ShowSnackbarMsg(GetText("PlayListDoesntExist")));
            }

            var file = pl.Items.FirstOrDefault(f => f.Id == id);

            if (file == null)
            {
                Logger.LogWarning($"{nameof(SetFileLoop)}: Couldnt update fileId = {id} because it doesnt exists");
                return(ShowSnackbarMsg(GetText("FileDoesntExist")));
            }

            file.Loop = loop;
            return(Task.CompletedTask);
        }
Esempio n. 12
0
        public Task PlayFileForMediaWebSocket(long id, long playlistId, bool force)
        {
            var playList = PlayLists.FirstOrDefault(pl => pl.Id == playlistId);

            if (playList == null)
            {
                Logger.LogWarning($"{nameof(PlayFileForMediaWebSocket)}: Couldnt play fileId = {id} because playlistId = {playlistId} doesnt exists");
                _appWebServer.OnServerMsg?.Invoke(GetText("PlayListDoesntExist"));
                return(Task.CompletedTask);
            }

            var file = playList.Items.FirstOrDefault(f => f.Id == id);

            if (file != null)
            {
                return(PlayFile(file, force));
            }
            Logger.LogWarning($"{nameof(PlayFileForMediaWebSocket)}: Couldnt play fileId = {id} because it doesnt exists");
            _appWebServer.OnServerMsg?.Invoke(GetText("FileDoesntExist"));
            return(Task.CompletedTask);
        }