0

我正在构建一个包含歌曲和视频上传的站点(类似于 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" />
4

1 回答 1

0

如果您阅读页面上的评论,您会发现这是一个安全问题。阅读下面的最后一段。

注意:对于在浏览器中运行的本地内容,仅当 SWF 文件和包含的网页位于本地受信任的安全沙箱中时,对 ExternalInterface.addCallback() 方法的调用才有效。

来自:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#addCallback()

这意味着除非您已经完成了为本地文件设置 Flash 播放器安全设置的繁琐工作,否则 ExternalInterface 调用仅在从“域”加载页面时才起作用。http://localhost计数,但任何file://请求都不会。

于 2013-07-01T02:44:52.850 回答