我正在构建一个包含歌曲和视频上传的站点(类似于 mySpace),因此文件存储在项目内的文件夹中。我正在尝试使用以下插件来播放这些歌曲: http: //kolber.github.io/audiojs/ 但如果文件在本地播放,它会要求添加“ExternalInterface.addCallback()”。我应该在哪里添加这个回调?我是 MVC4 世界的新手,所以欢迎任何人 :)
这是我的模型:Song.cs
namespace VPM.Models
{
//db model
public class Song
{
[Key]
public int userId { get; set; }
public string songName { get; set; }
public string songPath { get; set; }
public int like { get; set; }
public int unlike { get; set; }
public Boolean share { get; set; }
}
public class UploadMusic
{
[Required]
public int userId { get; set; }
[Required]
public string songName { get; set; }
[Required]
public string songPath { get; set; }
public Song getSong()
{
Song u = new Song { userId = this.userId, songName = this.songName, songPath = this.songPath };
return u;
}
}
}
这是我的控制器 - SongsController.cs
public class SongsController : Controller
{
//
// GET: /Songs/
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
VPMDB db = new VPMDB();
int id = Convert.ToInt32(Session["id"]);
String email ="";
var query = from u in db.users where u.userId.Equals(id) select u.Email;
bool flag = false;
foreach (var item in query)
{
flag = true;
email = item;
}
//if user exists
if (flag)
{
string UserDirectory = "C:\\Users\\dadaPC\\Desktop\\VPM\\VPM\\VPM\\UserFiles\\" + email + "\\music\\" + file.FileName.ToString();
file.SaveAs(UserDirectory);
var fileName = Path.GetFileName(file.FileName);
UploadMusic newsong = new UploadMusic();
newsong.userId = 11;
newsong.songName = file.FileName.ToString();
newsong.songPath = UserDirectory;
db.song.Add(newsong.getSong());
db.SaveChanges();
}
}
return RedirectToAction("Index");
}
}
这是我的观点 - index.cshtml
@model VPM.Models.Song
@{
ViewBag.Title = "Index";
}
<h2>Your Music</h2>
@using (Html.BeginForm("Index", "Songs", FormMethod.Post, new { enctype = "multipart/form-data" })){
<input type="file" name="file" id="file">
<input type="submit" />
}
<script src="/audiojs/audio.min.js"></script>
<script>
audiojs.events.ready(function() {
var as = audiojs.createAll();
});
</script>
<audio src="file:///C:/Users/dadaPC/Desktop/VPM/VPM/VPM/UserFiles/da@aa.com/music/01 A Word From The Author.mp3" preload="auto" />