HTML5视频寻址

14
如何让我的视频播放器跳转到特定时间?我已经尝试过了,当页面首次加载时(在Chrome中)它可以工作,但在其他浏览器中不行。我还有一个Flash备用方案可能会很麻烦,但现在优先考虑HTML方面的问题。主要问题是它在Chrome之外无法工作!编辑:现在在IE9、Chrome和Firefox中都可以工作。但是,它与Flash备用方案不能兼容!以下是我迄今为止的尝试。我目前正在使用以下JS:
   <script language="javascript">
     $(function () {
     var v = $("#video").get(0);
         $('#play').click(function(){
                v.play();
         });

        $('.s').click(function(){
            alert("Clicked: "+$(this).html() +"- has time of -" + $(this).attr('s') );
            v.currentTime = $(this).attr('s'); v.play();
        });
     });
    </script>

这是一个链接,指向以下内容:

<video id="video" controls width="500">  
        <!-- if Firefox -->  
        <source src="video.ogg" type="video/ogg" />  
        <!-- if Safari/Chrome-->  
        <source src="video.mp4" type="video/mp4" />  
        <!-- If the browser doesn't understand the <video> element, then reference a Flash file. You could also write something like "Use a Better Browser!" if you're feeling nasty. (Better to use a Flash file though.) -->  
        <object type="application/x-shockwave-flash" data="player.swf"
        width="854" height="504">
            <param name="allowfullscreen" value="true">
            <param name="allowscriptaccess" value="always">
            <param name="flashvars" value="file=video.mp4">
            <!--[if IE]><param name="movie" value="player.swf"><![endif]-->
            <p>Your browser can’t play HTML5 video.</p>
  </object>
    </video>

在具有类 s 和自定义属性 s=60 的按钮上下文中,用于表示“60秒”等。

2个回答

12
seekToTime:function( value )
{
    var seekToTime = this.videoPlayer.currentTime + value;
    if( seekToTime < 0 || seekToTime > this.videoPlayer.duration ) 
        return;

    this.videoPlayer.currentTime = seekToTime;
}

这是我们正在使用的搜索功能。它采用MooTools语法,但你会明白的。希望它有所帮助。


我现在修改了代码,以考虑到结束/开始溢出。但是关于Flash备用方案呢?我如何控制SWF?我需要额外的JQ吗? - JustAnotherDeveloper
接受此答案,因为我现在遇到的问题与该问题无关。 - JustAnotherDeveloper

1

我猜你是用JS和CSS构建了自己的控件?那么,你需要扩展你的SWF文件,以便可以从JavaScript中调用你的搜索函数。外部接口是你的好朋友:在ActionScript/Flash中:

 import flash.external.ExternalInterface; 

 ExternalInterface.addCallback( "methodName", this, method ); 

 function method() { trace("called from javascript"); }

通过 JavaScript 调用此函数

function callAS() {
    swf.methodName();
}

我目前正在使用基本的Flash视频播放器,计划使用FlowPlayer或JWPlayer等播放器。只需要找出如何将它们与我的事件连接起来 :) - JustAnotherDeveloper

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接