2014-02-09 31 views
0

我有一個ASP.NET MVC站點和JPlayer插件,並且我想向數據庫添加一個歷史記錄條目。如何在JPlayer的結束事件中獲得當前歌曲的標題

當我通過當前曲目的AJAX標題發送結束事件時,我會得到下一首曲目的標題。

例如:

播放列表:

  • 1)首先Song.mp3的
  • 2)第二Song.mp3的

當第一歌曲結束,我得到在第二控制器song.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

嗯,解決方案,更好的解決方案可能是答案:)

@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');" + 
    "}});}"); 
} 
相關問題