Сохранение громкости плеера
This commit is contained in:
30
PlaylistShared.Pwa/Services/PlayerStorage.cs
Normal file
30
PlaylistShared.Pwa/Services/PlayerStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,4 @@ public class TokenStorage
|
||||
await _js.InvokeVoidAsync("localStorage.removeItem", TokenKey);
|
||||
await _js.InvokeVoidAsync("localStorage.removeItem", RefreshTokenKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user