【问题标题】:how to display the alert when the iframe embedded video playing,pausing,buffering如何在 iframe 嵌入视频播放、暂停、缓冲时显示警报
【发布时间】:2014-01-12 16:05:13
【问题描述】:

当我们使用jquery点击它时,我正在用相应的iframe替换特定的div内容,如何在动态加载iframe中的视频播放、暂停、缓冲时显示警报。

谁能告诉我如何解决这个问题..

【问题讨论】:

    标签: php jquery youtube youtube-api


    【解决方案1】:
    Try This Example : 
      <html>
            <head>
                <script src = "http://www.youtube.com/player_api"></script>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <link rel="stylesheet" href="style.css" type="text/css"     media="screen" charset="utf-8">
            </head>
            <body dir = "rtl">
                <iframe id="player" width="640" height="360"   src="http://www.youtube.com/embed/-cSFPIwMEq4" onload="floaded()" frameborder="0" allowfullscreen="">
                </iframe>
        <script>
        //onYouTubePlayerAPIReady
        var player;
          function floaded(){
            player = new YT.Player('player', {
              videoId: '-cSFPIwMEq4',
              events:
               {      
                'onStateChange': function (event)
                    {
                    if (event.data == YT.PlayerState.PLAYING)                                    {  alert("Playing.."); }
                    else if (event.data == YT.PlayerState.PAUSED)
                       { alert ("Paused.."); }
                    else
                    alert ("Buffering/Video Ended");                
    
                     }
               }
    
            });
          }
    
        </script>
    
        </body>
        </html>
    

    【讨论】:

      【解决方案2】:

      <!DOCTYPE html>
      <html>
        <body>
          <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
         <!-- <div id="player"></div>-->
      <iframe id="player" type="text/html" width="640" height="390"
        src="http://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1"
        frameborder="0"></iframe>
          <script>
            // 2. This code loads the IFrame Player API code asynchronously.
            var tag = document.createElement('script');
      
            tag.src = "https://www.youtube.com/iframe_api";
            var firstScriptTag = document.getElementsByTagName('script')[0];
            firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      
            // 3. This function creates an <iframe> (and YouTube player)
            //    after the API code downloads.
            var player;
            function onYouTubeIframeAPIReady() {
              player = new YT.Player('player', {
                //height: '390',
                //width: '640',
                videoId: 'M7lc1UVf-VE',
                events: {
                  'onReady': onPlayerReady,
                  'onStateChange': onPlayerStateChange
                }
              });
            }
      
            // 4. The API will call this function when the video player is ready.
            function onPlayerReady(event) {
              event.target.playVideo();
            }
      
            // 5. The API calls this function when the player's state changes.
            //    The function indicates that when playing a video (state=1),
            //    the player should play for six seconds and then stop.
            var done = false;
            function onPlayerStateChange(event) {
               if (event.data == YT.PlayerState.PLAYING) {
                alert('Video Playing');
         
              }
      		else if (event.data == YT.PlayerState.PAUSED) {
                alert('Video Paused');
         
              }}
          </script>
        </body>
      </html>

      【讨论】:

      • 这是 100% 成功......试试这个。如果有任何问题给我发电子邮件 kishor00977@gmail.com
      猜你喜欢
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多