Files
deepdrft/DeepDrftWeb.Client/Clients/TrackMediaClient.cs
T
daniel-c-harvey 66d800bd26 Front End Work
- Redesign component wiring for audio playback
 - Removed playback logic from the player control and moved it to injectable audio player engine service
 - Chunked/buffered stream loading from Content API passed to Web Audio API playback in 8K blocks
2025-09-06 13:39:26 -04:00

36 lines
983 B
C#

using Microsoft.Extensions.DependencyInjection;
namespace DeepDrftWeb.Client.Clients;
public class TrackMediaResponse
{
public Stream Stream { get; }
public long ContentLength { get; }
public TrackMediaResponse(Stream stream, long contentLength)
{
Stream = stream;
ContentLength = contentLength;
}
}
public class TrackMediaClient
{
private readonly HttpClient _http;
public TrackMediaClient(IHttpClientFactory httpClientFactory)
{
_http = httpClientFactory.CreateClient("DeepDrft.Content");
}
public async Task<TrackMediaResponse> GetTrackMedia(string trackId)
{
var response = await _http.GetAsync($"api/track/{trackId}");
response.EnsureSuccessStatusCode();
var contentLength = response.Content.Headers.ContentLength ?? 0;
var stream = await response.Content.ReadAsStreamAsync();
return new TrackMediaResponse(stream, contentLength);
}
}