Сохранение громкости плеера
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
|
||||
[Inject] protected IJSRuntime JS { get; set; } = null!;
|
||||
[Inject] private TokenStorage TokenStorage { get; set; } = null!;
|
||||
[Inject] private PlayerStorage PlayerStorage { get; set; } = null!;
|
||||
[Inject] private AuthenticationStateProvider AuthProvider { get; set; } = null!;
|
||||
[Inject] private ISnackbar Snackbar { get; set; } = null!;
|
||||
|
||||
@@ -76,6 +77,8 @@
|
||||
if (firstRender)
|
||||
{
|
||||
await EnsureAudioModuleAsync();
|
||||
await ChangeVolume(await PlayerStorage.GetVolumeAsync());
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +100,7 @@
|
||||
if (double.IsNaN(currentTime) || double.IsNaN(duration) || double.IsInfinity(currentTime) || double.IsInfinity(duration))
|
||||
return;
|
||||
if (duration <= 0) return;
|
||||
|
||||
|
||||
_currentProgress = (currentTime / duration) * 100;
|
||||
_currentTime = FormatTime(currentTime);
|
||||
// Длительность не обновляем здесь
|
||||
@@ -123,10 +126,10 @@
|
||||
private async Task<bool> CheckAuthAsync()
|
||||
{
|
||||
if (!RequireAuth) return true;
|
||||
|
||||
|
||||
var authState = await AuthProvider.GetAuthenticationStateAsync();
|
||||
var isAuthenticated = authState.User.Identity?.IsAuthenticated == true;
|
||||
|
||||
|
||||
if (!isAuthenticated)
|
||||
{
|
||||
Snackbar.Add("Воспроизведение доступно только авторизованным пользователям", Severity.Warning);
|
||||
@@ -141,13 +144,13 @@
|
||||
|
||||
var tokens = await TokenStorage.GetTokensAsync();
|
||||
var accessToken = tokens.token;
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(accessToken) && string.IsNullOrWhiteSpace(SharedPlaylistId))
|
||||
{
|
||||
Snackbar.Add("Токен авторизации не найден. Пожалуйста, войдите заново.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var streamUrl = new Uri(Http.BaseAddress!, $"/api/audio/track/{trackId}").ToString();
|
||||
|
||||
await EnsureAudioModuleAsync();
|
||||
@@ -160,7 +163,7 @@
|
||||
public async Task PlayAsync()
|
||||
{
|
||||
if (!await CheckAuthAsync()) return;
|
||||
|
||||
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("play");
|
||||
_isPlaying = true;
|
||||
@@ -226,6 +229,8 @@
|
||||
var volume = value / 100;
|
||||
await _audioElement.InvokeVoidAsync("setVolume", volume);
|
||||
_isMuted = false;
|
||||
_currentVolume = value;
|
||||
await PlayerStorage.SetVolumeAsync(value);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user