1

我想知道如何在flowplayer中获取当前播放时间?

这行代码即使在播放过程中也会返回异常: playertime = $f().getTime();

我包括调用 getTime() 的 Javascript

Javascript:享受.js

setInterval(function() {
    var playertime = 0;
    var duration = 0;
    try {
        duration = $f().getClip().duration;
        // alert(duration); /* This works fine*/
        playertime = $f().getTime(); /* This throws an exception outside try-catch. Uncaught exception: Error in Actionscript. Use a try/catch block to find error.*/
        if (isNaN(playertime)) {
            // no clip running
            playertime = 0;
        }
    } catch (err) {
        playertime = 0;
    }
    $.ajax({
        url : "/enjoy_ajax/",
        type : "POST",
        data : {
            code : $('#code').val(),
            playback : playertime
        }
    }).done(function() {
        $(this).addClass("done");
    });
}, 1000 * 60 * 0.05); // where X is your every X minutes

这是包含enjoy.js的 HTML

HTML

{% extends "movies/template.html" %}
{% load aws-tags %}
{% block title %}{{ movie.title }}{% endblock %}
{% block js %}
<script src="https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer-3.2.10.min.js"></script>
<script src="https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer.ipad-3.2.9.min.js"></script>
{% endblock %}
{% block content %}

<div id="title">
    Enjoy The Show!
</div>
<div id="movie_player">

    <a id="player" href="{{signed_url}}"> </a>

    <script type="text/javascript">
        $(document).ready(function() {
            if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)) {

                $f("player", {
                    src : "https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer.commercial-3.2.11.swf",
                    wmode : 'opaque'
                }, {
                    key : '{{player_key}}',
                    clip : {
                        // preserve aspect ratios
                        scaling : 'fit'
                    }
                }).ipad({
                    simulateiDevice : true,
                    controls : true
                });
            } else {
                $f("player", {
                    src : "https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer.commercial-3.2.11.swf",
                    wmode : 'opaque'
                }, {
                    key : '{{player_key}}',
                    clip : {
                        provider : 'rtmp',
                        autoPlay : true,
                        urlResolvers : 'brselect',
                        // preserve aspect ratios
                        scaling : 'fit',
                        bitrates : [

                        // use the 800 kbps item by default, the SD item, marked with sd: true
                        {
                            url : "mp4:{{movie.mp4_file_lo|aws_sign_cf_stream}}",
                            bitrate : 320,
                            sd : true,
                            isDefault : false
                        },

                        // this is the HD item, marked with hd: true
                        {
                            url : "mp4:{{movie.mp4_file_hi|aws_sign_cf_stream}}",
                            bitrate : 1066,
                            hd : true,
                            isDefault : true
                        }]
                    },
                    plugins : {
                        brselect : {
                            url : "https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer.bitrateselect-3.2.10.swf",

                            // comment this out in production
                            onStreamSwitch : function(newItem) {
                                $f().getPlugin('content').setHtml("Switched to: " + newItem.streamName);
                            },
                            hdButton : {
                                // custom labels for the HD splash
                                splash : false,
                                place : 'controls'
                            }
                        },
                        rtmp : {
                            url : 'https://s3.amazonaws.com/MY_AMAZON_S3_BUCKET/flowplayer/flowplayer.rtmp-3.2.10.swf',
                            netConnectionUrl : 'rtmpe://{{cloudfront_domain}}/cfx/st'
                        }
                    }
                }).ipad();
            }
        });

    </script>

</div>
<hr id="green_hr" />
<div id="movie_poster">
    <img src="{{ movie.poster_url }}" alt ="" />
</div>
<div id="movie_title">
    {{ movie.title }}
</div>
<div id="movie_description">
    {{ movie.description }}
</div>
<input type="hidden" id="code" name="code" value="{{code}}" />
<script type="text/javascript" src="{{STATIC_URL}}javascript/enjoy.js"></script>
{% endblock %}
4

1 回答 1

5
     var playerapi = flowplayer($(".flowplayer"));
     alert(playerapi.ready ? playerapi.video.time : 0);

用这个

在这里,alert(playerapi.ready ? playerapi.video.time : 0) 这个节目是当前时间。

于 2013-06-26T11:00:45.057 回答