Сохранение громкости плеера

This commit is contained in:
FrigaT
2026-04-14 14:52:46 +03:00
parent 9e8bb0db75
commit 68887284c1
4 changed files with 43 additions and 7 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.JSInterop;
namespace PlaylistShared.Pwa.Services;
public class PlayerStorage
{
private readonly IJSRuntime _js;
private const string VolumeKey = "audio_player_volume";
public PlayerStorage(IJSRuntime js) => _js = js;
public async Task SetVolumeAsync(double volume)
{
await _js.InvokeVoidAsync("localStorage.setItem", VolumeKey, volume);
}
public async Task<double> GetVolumeAsync()
{
var volume = await _js.InvokeAsync<string>("localStorage.getItem", VolumeKey);
if (double.TryParse(volume, out var result))
{
result = Math.Clamp(result, 0, 100);
return result;
}
return 0;
}
}

View File

@@ -28,4 +28,4 @@ public class TokenStorage
await _js.InvokeVoidAsync("localStorage.removeItem", TokenKey);
await _js.InvokeVoidAsync("localStorage.removeItem", RefreshTokenKey);
}
}
}