0

私のスタッフと私は、Youtubeビデオの特定のポイントに表示される非表示のコンテンツを含むページを設定する方法を研究しています。

最初はsettimeout()関数を使用してすぐにそこに到達しましたが、これはビデオの時間ではなく、経過時間によってのみ行われます。たとえば、指定した時間が経過した後に動画が一時停止された場合でも、非表示のコンテンツが表示されます。

これまでのコードは次のとおりです。

<p>
<script type="text/javascript">// <![CDATA[
    function showIt() {
        document.getElementById("hid").style.display = "block";
    }
    setTimeout("showIt()",30000);
    // 1000 = 1 sec | 60000 is 1 minute
    // ]]></script>
</p>
<p>{youtube}Yhwk5OorNPw&amp;rel=0&amp;autoplay=1&amp;showinfo=0&amp;version=3|640|390{/youtube}</p>
<div id="hid" style="display: none;">
    <p style="text-align: center;"><span style="font-size: 32pt; color: #ff6600;"><strong><a target="_blank" href="http://www.youtube.com/watch?v=K80leSIhSD4"><span style="color: #ff6600;">HEY RICK - You can buy a Website Now!</span></a></strong></span></p>
</div>

ビデオでトリガーする方法を知っている場合は、特定の時間になります。これは非常に役立ちます。

4

1 に答える 1

0

The best way is get current YouTube video time in every seconds .

You can use setInterval to call the function every seconds. In that function get current YouTube video time and based on that do your operations.I think this is a reliable way

Please check this answer .From the answer you can understand how to get current play time from YouTube player. Hope it helps you

EDIT

I guess you want to show the hidden content after 30 second of the video. To do so you must capatur the youtube video current time.To get current time you must use youtube API .You can leanr more infor about API .You will get more info about API from here

Once you get the current time ( you will get that in seconds) if u use api you can use following logic to show up the hidden content

<script type="text/javascript">
var timerForLoadingResult=  setInterval(showIt,1000);//call the fnction in every seconds.
     function showIt() {
       var currentTime=GetCurrentYoutubeTime(); // this function must return a current time in seconds
       if(currentTime>=30) // i guess u need to show up after30 th second
        {
          document.getElementById("hid").style.display = "block";
          clearInterval(timerForLoadingResult);        //it will clear the timer, so the function will not excecute again
        }
      }
     function  GetCurrentYoutubeTime()
    {
      // fetch youtube video time using api . and return that value
    }
 </script>
于 2011-10-05T17:45:27.040 に答える