Strobe Media Playback(OSMF)事件

时间:2013-02-06 14:21:07

标签: events adobe osmf strobe-media-playback

有人知道Strobe Media PlaybackOSMF)是否包含以下事件:

  1. 流式传输已结束
  2. 开始流媒体
  3. 流式传输错误
  4. 要通过JavaScript访问它吗?

    我试过这个但没有快乐。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Strobe Media Playback</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
        <script type="text/javascript">         
    
            // Create a StrobeMediaPlayback configuration 
            // http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv
            // http://osmf.org/dev/1.6-sprint-2/hello-world-jquery-plugin.html#
            var parameters =
                {
                    src: "http://stream.flowplayer.org/bauhaus/624x260.mp4"
                ,   autoPlay: true
                ,   controlBarAutoHide: false
                ,   javascriptCallbackFunction: "onJavaScriptBridgeCreated"
                };
    
            // Embed the player SWF:            
            swfobject.embedSWF
                ( "StrobeMediaPlayback.swf"
                , "strobeMediaPlayback"
                , 640
                , 480
                , "10.1.0"
                , {}
                , parameters
                , { allowFullScreen: "true"}
                , { name: "strobeMediaPlayback" }
                );
    
            function completeFunc(time, playerId) {
                //var player = document.getElementById(playerId);
                alert("!!!");
            }
    
            function onCurrentTimeChange(time, playerId)
            {
                document.getElementById("currentTime").innerHTML = time;        
            }
    
            function onDurationChange(time, playerId)
            {
                document.getElementById("duration").innerHTML = time;   
            }       
            var player = null;
            function onJavaScriptBridgeCreated(playerId)
            {
                if (player == null) {
                    player = document.getElementById(playerId);
    
                    // Add event listeners that will update the 
                    player.addEventListener("currentTimeChange", "onCurrentTimeChange");
                    player.addEventListener("durationChange", "onDurationChange");
    
                    player.addEventListener("complete", "completeFunc");
    
                    // Pause/Resume the playback when we click the Play/Pause link
                    document.getElementById("play-pause").onclick = function(){
                        var state = player.getState();
                        if (state == "ready" || state == "paused") {
                            player.play2();
                        }
                        else 
                            if (state == "playing") {
                                player.pause();
                            }
                        return false;
                    };
                }
            }
        </script>   
      </head>
      <body>
        <div>
            <div>
                <span id="currentTime" /> ... </span> : <span id="duration" /> ... </span>
            </div>   
            <a href="#" id="play-pause">Play/Pause</div>  
        </div>
        <div id="strobeMediaPlayback">
          <p>Alternative content</p>
        </div>
      </body>
    </html>
    

    谢谢!

    P.S。我可以看到here,我们可以使用 STATE 变量来检测视频的结尾。 因此,在视频结束时,它会转到“ PAUSED ”。我们可以这样使用吗?


    更新

    我发现onJavaScriptBridgeCreated方法没有触发。 SMP的所有例子也是如此。

    有任何线索吗?

2 个答案:

答案 0 :(得分:2)

是的。

function changeVidSrc(url, posterUrl, id, width, height, autoplay) {

var flashvars =
{
    src: url,
    autoPlay: autoplay,
    controlBarAutoHide: true,
    poster: posterUrl,
    skin: 'skinPath', //i just needed skin, remove if not needed
    javascriptCallbackFunction: "onJavaScriptBridgeCreated"

};

var parameters = { allowFullScreen: "true"};

var attributes = { name: id };

// Embed the player SWF:
    swfobject.embedSWF
        ('/swfs/StrobeMediaPlayback.swf',
            id, width, height,
            "10.1.0",
            '',
            flashvars,
            parameters,
            attributes
        );

}

一些重要细节:
1.我无法正确调试firebug。我无法理解行为。
2.在name对象中传递attributes对于FF非常重要。否则回调触发器,但没有事件处理
我还建议将全局var player和处理函数放在最上面。

答案 1 :(得分:0)

流式传输结束:

var onJavaScriptBridgeCreated = function (event) {
    if (event === ''onJavaScriptBridgeCreated'') {
        var player = document.getElementById('the id of the object tag');
        var callback = function(event){console.log(event);};
        //stopped
        player.addEventListener("complete", "callback");
        //started
        player.addEventListener("playStateChange", "callback");
        //error
        player.addEventListener("mediaError", "callback");
    }
}