我有一个ASP.NET MVC站点和JPlayer插件,我想在数据库中添加一个历史记录条目。
当我在结束事件发生时通过当前曲目的AJAX标题发送时,我得到下一曲目的标题。
例如:
播放列表:
当第一首歌结束时,我进入控制器第二首歌.mp3
查看:
@Html.Raw("<script>$(document).ready(function() {");
@Html.Raw("var cssSelector = { jPlayer: '#jquery_jplayer_1', cssSelectorAncestor: '#jp_container_1' };");
@Html.Raw("var playlist = [");
foreach(var song in Model.Song) {
@Html.Raw("{ title : '" + @song.song_name + "' ," + "mp3 : '/Content/Uploads/" + @song.song_path + "'},")
}
@Html.Raw("];");
@Html.Raw("var actionUrl = '" + @Url.Action("History", "Music") + "';");
@Html.Raw("var options = { swfPath : '/Scripts/jplayer', supplied : 'mp3', ");
if(HttpContext.Current.User.Identity.IsAuthenticated) {
@Html.Raw(" ended : function () {" +
"$.ajax({" +
"type: 'POST'," +
"url : actionUrl," +
"data : { isEnded: 'true', trackname: myPlaylist.playlist[myPlaylist.current].title, albumId : " + "\"" + @Model.album_id.ToString() + "\"}," +
"success: function (data) {}," +
"error: function (xhr, ajaxOptions, thrownError) {" +
"alert('Cant add to history');" +
"}});}");
}
@Html.Raw("};");
@Html.Raw("var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);");
提前致谢:)
答案 0 :(得分:0)
嗯,解决方案,更好的解决方案可以作为答案:)
@Html.Raw("var actionUrl = '" + @Url.Action("History", "Music") + "';");
@Html.Raw("var curTrack;");
@Html.Raw("var options = { swfPath : '/Scripts/jplayer', supplied : 'mp3', ");
if(HttpContext.Current.User.Identity.IsAuthenticated) {
@Html.Raw(" play : function () {" + "curTrack = myPlaylist.playlist[myPlaylist.current].title;},");
@Html.Raw(" ended : function () {" +
"$.ajax({" +
"type: 'POST'," +
"url : actionUrl," +
"data : { isEnded: 'true', trackname: curTrack, albumId : " + "\"" + @Model.album_id.ToString() + "\"}," +
"success: function (data) {}," +
"error: function (xhr, ajaxOptions, thrownError) {" +
"alert('Cant add to history');" +
"}});}");
}