2013-05-06 98 views
1

我在一个页面上有两个视频,用VideoJS实现。我想让他们敏感,并找到关于此主题的以下文章:Making Video.js Fluid for RWDVideoJS敏感的两个视频

但不幸的是,我无法让它与两个视频一起工作,无论我尝试过它总是只与其中一个工作..你有任何想法,我必须改变JavaScript代码,使它与两个工作?我甚至试图做两个函数并重命名所有变量。

这里是我的示例HTML:

<div class="videoWrapper"> 
    <video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" poster="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01_still.jpg" data-setup='{ "controls": true, "autoplay": false, "preload": "auto" }'> 
     <source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01.flv" type='video/flv'> 
     <source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video1/spot_01.mp4" type='video/mp4'> 
    </video> 
    <video id="my_video_2" class="video-js vjs-default-skin" controls preload="auto" poster="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02_still.jpg" data-setup='{ "controls": true, "autoplay": false, "preload": "auto" }'> 
     <source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02.flv" type='video/flv'> 
     <source src="<?php echo get_bloginfo('template_url'); ?>/assets/videos/video2/spot_02.mp4" type='video/mp4'> 
    </video> 
</div> 

CSS:

.videoWrapper video { 
max-width: 100% !important; 
height: auto !important; 
} 

#my_video_1, 
#my_video_2 { 
    width:100% ; 
    height:auto ; 
} 

和JS:

_V_("my_video_1").ready(function(){ 
var myPlayer = this; // Store the video object 
var aspectRatio = 9/16; // Make up an aspect ratio 

function resizeVideoJS(){ 
    // Get the parent element's actual width 
    var width = document.getElementById(myPlayer.id).parentElement.offsetWidth; 
    // Set width to fill parent element, Set height 
    myPlayer.width(width).height(width * aspectRatio); 
} 

resizeVideoJS(); // Initialize the function 
window.onresize = resizeVideoJS; // Call the function on resize 
}); 
+0

为简洁起见,您可能会忽略它,但您是否在my_video_1和my_video_2上调用了'.ready'?如果没有,那么我会猜测那是你的问题。 – bmceldowney 2013-05-10 22:57:21

+0

是的,我确实在两者上都调用了它。 – Sebsemillia 2013-05-14 21:07:21

回答

1

我一直在努力的脚本与多个视频播放器特价使用视频js - 这也是响应。你可以在这里找到我的文章(这也是一个例子)= http://www.andy-howard.com/videojsmultipleresponsivevideos/index.html

这还包括一个提供的回调函数,如果你需要的话。

+0

下面是一个很好的例子,说明为什么答案应该总是包含代码,而不仅仅是代码的链接。 404错误! – rlcabral 2013-11-12 16:47:08

+0

对不起,我必须将2个教程合并为1才能使其工作。这里是新的url = http://www.andy-howard.com/recreate-bbc-iplayer/index.html在这个例子中,我不得不提供链接,因为很多东西都是从原始视频js文件夹我被提供了。如果有1或2个代码示例没有问题,但是整个文件夹中充满变化的内容太多,无法在此处进行描述。 – 2013-11-13 10:58:56