mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-05 07:36:03 +02:00
feat: enhance audio playback features and UI, including audio player dialog and improved file size handling
This commit is contained in:
@@ -8,6 +8,14 @@ public class AudioPlaybackService
|
||||
private readonly Player _player = new();
|
||||
|
||||
public bool IsPlaying => _player.Playing;
|
||||
public bool IsPaused => _player.Paused;
|
||||
|
||||
public event EventHandler? PlaybackFinished;
|
||||
|
||||
public AudioPlaybackService()
|
||||
{
|
||||
_player.PlaybackFinished += (s, e) => PlaybackFinished?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public async Task PlayAsync(string filePath)
|
||||
{
|
||||
@@ -24,6 +32,32 @@ public class AudioPlaybackService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PauseAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_player.Playing && !_player.Paused)
|
||||
await _player.Pause();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to pause audio playback");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ResumeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_player.Paused)
|
||||
await _player.Resume();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to resume audio playback");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
{
|
||||
try
|
||||
@@ -36,4 +70,16 @@ public class AudioPlaybackService
|
||||
Log.Warning(ex, "Failed to stop audio playback");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetVolumeAsync(byte volume)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _player.SetVolume(Math.Min(volume, (byte)100));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to set audio volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user