1

我正在开发一个视频应用程序,我想使用视频播放器 API (Flowplayer) 跟踪用户的操作。我通过在每个事件上设置一个事件侦听器来处理“播放、暂停、恢复等”。使用 javascript 的事件。捕获事件后,我正在调用放置在服务器端的静态方法,以便将操作写入数据库(并向用户隐藏跟踪信息)。

这是我现在得到的:

JS代码:

<script type="text/javascript">
// bind listeners to all players on the page
flowplayer(function (api, root) {
    api.bind("pause", function () {
        console.info("pause", api.paused);

        var timePassed = api.video.time;
        @{
            Reporter.ReportPause(timePassed);
        }
        //... more code  ...

</script>

C#代码:

public static void ReportPause ( string timePassed)
{
    // do something with timePassed
}

我遇到了一个例外:“无法解析符号'timePassed'”。

我怎样才能以正确/优雅的方式做到这一点(以最小的开销)。

谢谢大家,YNWA

4

1 回答 1

0
<script type="text/javascript">
        // bind listeners to all players on the page
        flowplayer(function (api, root) {
            api.bind("pause", function () {
                console.info("pause", api.paused);

                var timePassed = $.flowplayer().getTime();
                    $.ajax({
        url: '/Home/ReportPause',
        type: 'POST',
        dataType: "json",
        data: { timePassed: timePassed },
        error: function (a, b, c) { onError(a, b, c, parameters); },
        success: function (data) { onSuccess(data, parameters); }
    });
                });
            }
    </script>


// Controller
public class HomeController{
    public JsonResult ReportPause(string timePassed)
    {
         TimePassedClass.ReportPause(timePassed);
         // more code
    }
}
public static class TimePassedClass
{
      public static void ReportPause(string timePassed)
       {
          // your logic
       }
}
于 2013-09-03T10:31:07.657 回答