C
C#14mo ago
トラム

❔ Streama audiofile with capability to skip to a specific duration

So for startes, I am making a .net core webapi that uses youtubeAPI to search for music and uses youtube-dlp and ffmpeg to download the tracks as my final project, the API is for both a web and desktop app (still thinking bout name ^^) that lets you make playlists (tracks from youtube) and download them . [I know youtube is not the ideal choice, but besides point].
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"wwwroot\\Tracks\\{trackId}.flac");

try
{
var stream = System.IO.File.OpenRead(filePath);

Response.Headers.Add("Accept-Ranges", "bytes");
Response.Headers.Add("Content-Disposition", $"inline; filename={Path.GetFileName(filePath)}");
Response.Headers.Add("Content-Type", "audio/flac");

return Ok(new BufferedStream(stream));


}
catch (FileNotFoundException ex)
{
this._logger.LogError("Track File not fount. \nDetails: {details}",ex.Message );
return NotFound("Track no longer exists");
}
catch (IOException ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"wwwroot\\Tracks\\{trackId}.flac");

try
{
var stream = System.IO.File.OpenRead(filePath);

Response.Headers.Add("Accept-Ranges", "bytes");
Response.Headers.Add("Content-Disposition", $"inline; filename={Path.GetFileName(filePath)}");
Response.Headers.Add("Content-Type", "audio/flac");

return Ok(new BufferedStream(stream));


}
catch (FileNotFoundException ex)
{
this._logger.LogError("Track File not fount. \nDetails: {details}",ex.Message );
return NotFound("Track no longer exists");
}
catch (IOException ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
so anyways everything works ok I guess, the issue is in the webapp, you cant skip to a specific timestamp and when attempting to do so, it just go back to 00:00 and I don't want to send whole file at once to client since FLAC files can get up to 40Mb each and could be irritating. and m trying to stream file bit by bit and still have capability to skip, any idead ?
1 Reply
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server