2014-02-09 1 views
0

ASP.NET MVC 사이트와 JPlayer 플러그인이 있으며 데이터베이스에 기록 항목을 추가하고 싶습니다.JPlayer에서 종료 된 이벤트에서 현재 노래의 제목을 얻는 방법

종료 된 이벤트가 발생하면 현재 트랙의 AJAX 제목으로 보낼 때 다음 트랙의 제목이 표시됩니다. 예를 들어

:

재생 목록 :

  • 1) 우선 song.mp3
  • 2) 제 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');" + 
    "}});}"); 
} 
관련 문제