2013-04-05 127 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