Added functionality to stream a song. I just need to test it. #7
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -32,5 +33,36 @@ namespace Icarus.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP endpoints
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var songStore= HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
|
||||
|
||||
var song = songStore.GetSong(new Song
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
|
||||
|
||||
var mem = new MemoryStream();
|
||||
|
||||
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
stream.CopyToAsync(mem);
|
||||
}
|
||||
|
||||
mem.Position = 0;
|
||||
|
||||
_logger.LogInformation("Starting to stream song...>");
|
||||
Console.WriteLine("Starting to streamsong...");
|
||||
|
||||
return File(mem, "application/octet-stream", Path.GetFileName(song.SongPath));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user