Just put that code in a controller method, image will be loaded asynchronously (in this example controller method accepts file name as parameter, it may not be your case):
public ActionResult GetImage(string file)
{
var file12 = TagLib.File.Create(file);
if (file12.Tag.Pictures.Length >= 1)
{
string fileName = Path.ChangeExtension(
Path.GetFileName(file), ".jpg");
return base.File(
(byte[])(file12.Tag.Pictures[0].Data.Data),
"image/jpeg", fileName);
}
// You have to handle this case
return null;
}
Controller.File() method will do all the dirty job for you. For clarity in this example I omitted rescaling, just copy & paste your code there if needed. Please note you have to return something when no image is not available (a default thumbnail?), you may even return a HTTP error with:
return HttpNotFound();
Your HTML will be for example like this:
<img
src='@Url.Action("GetImage", new { file = "filenamehere.mp3" })'
alt='thumbnail' />
Please note that here I assumed your image is in JPG format, if it's not you may need to convert it to a known format to return proper MIME type (to detect MIME type from byte stream is possible too, check this post here on SO).