2013-04-05 119 views
1

喜,iframe的YouTube視頻控制

我真的很新的JavaScript和HTML5(剛開始3個星期前),所以我的問題都將可能看起來有點笨。

所以我想知道,如果它那更多鈔票停止與mouseleave.function YouTube視頻......

我已經在我的網站上的音樂播放至極,當我翻轉我的YouTube視頻音樂停止,我沒有這樣說:

$(video).mouseenter(function(){ 
    audioElement.pause(); 
}); 

比我可以玩YouTube視頻...

,當我離開的視頻播放器,音樂又在繼續,我用這個:

$(video).mouseleave(function(){ 
    audioElement.play(); 
}); 

但我想使YouTube視頻停在同一個時間,因爲視頻的聲音,而我的背景音樂聲中玩耍......

$(video).mouseleave(function(){ 
    audioElement.play(); **Something here to pause the youbevideo** 
}); 

這可能嗎? 我想保留YouTube視頻的版本,因爲我使用fitvids來調整我的視頻。

感謝

皮埃爾 srry,我的英語...

這裏是我的解決方案,拉維。

所以解決方案是將YouYube API腳本從外部js移動到主html。

http://users.skynet.be/fc864408/version9.html

<body> 

     <div class="tf_content" id="page4"> 
     <div class="container"> 
      <div class="vendor" id="video"> 
    <div id="player"></div> 


      </div> 
     </div> 
     </div> 




     <!-- The JavaScript --> 

     <script> 

     var tag = document.createElement('script'); 
tag.src = "https://www.youtube.com/iframe_api"; 
     var firstScriptTag = document.getElementsByTagName('script')[0]; 
     firstScriptTag.parentNode.insertBefore(tag, firstScriptTag) 

     var player; 
     function onYouTubeIframeAPIReady() { 
     player = new YT.Player('player', { 
      height: '420', 
      width: '640', 
      videoId: 'lVQzIwpClXA?theme=light&color=white&autohide=0&autoplay=0&showinfo=0&rel=1&controls=1;', 
      events: { 
      'onReady': onPlayerReady, 
      'onStateChange': onPlayerStateChange 
      } 
     }); 
     } 
     function onPlayerReady(event) { 

     } 
     var done = false; 
     function onPlayerStateChange(event) { 
     if (event.data == YT.PlayerState.PLAYING) { 
    audioElement.volume=0; 
      done = true; 
     } 
     } 


    video = document.getElementById("video"); 




      $(video).mouseleave(function(){ 
        player.stopVideo() 
       up(); 
       }); 



$(".container").fitVids(); 

現在的作品......影片根據窗口大小調整。

+0

你實際使用的API或者你只是嵌入的iframe?如果您使用的是API,請參閱以下文檔:https://developers.google.com/youtube/iframe_api_reference#Getting_Started – 2013-04-05 23:12:31

+0

我使用iframe,因爲我想使用fitvids插件,我試着使用api版本並達到我的暫停視頻的目標,但fitvids插件不再工作。 – 2013-04-05 23:40:36

+0

爲什麼不使用的iFrame API這樣的: https://developers.google.com/youtube/iframe_api_reference#Getting_Started 然後,在onPlayerReady功能,添加一行: '$('#球員)。 fitVids()',所以你可以保持對播放器元素的控制?你現在的方式,你不能訪問播放器元素。 – 2013-04-05 23:53:51

回答

0

只需使用(VideoElementID).play()和(VideoElementID).pause()在鼠標事件上播放/暫停視頻。您不需要單獨播放/暫停音頻和視頻。

問候, 拉維

+0

嗨Ravi,謝謝你的回答,但我不能使用(VideoElementID).play()或暫停()爲youtubevideo – 2013-04-05 23:25:15

+0

這裏是網站鏈接:: http://users.skynet.be/fc864408/version5 .html只是一次在正確的地方。謝謝 – 2013-04-05 23:35:20

+0

你無法獲得視頻元素ID,然後使用JQuery或Javascript播放/暫停功能?這是你的問題嗎? – 2013-04-06 00:14:38