Added functionality to stream a song. I just need to test it. #7

This commit is contained in:
amazing-username
2019-05-26 00:59:32 +00:00
parent 801a60e631
commit 05a33d4d9e
3 changed files with 53 additions and 17 deletions
+32
View File
@@ -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
}
}