简体   繁体   English

jwplayer导致平板电脑上出现动画错误

[英]jwplayer causes animation errors on tablet

This issue has been solved. 此问题已得到解决。 See the JSFiddle examples below to see the original errors, and scroll to solution to see the working version. 请参阅下面的JSFiddle示例以查看原始错误,并滚动到解决方案以查看工作版本。

JWPlayer v6: Link to preview on tablet devices (JSFiddle) Link to view full code (JSFiddle) JWPlayer v6: 链接以在平板电脑设备上预览 (JSFiddle) 链接以查看完整代码 (JSFiddle)

JWPlayer v5: Link to preview on tablet devices (JSFiddle) Link to view full code (JSFiddle) JWPlayer v5: 链接以在平板电脑设备上预览 (JSFiddle) 链接以查看完整代码 (JSFiddle)

2/10/14 (UPDATE) - In the JSFiddle example provided, I updated jwplayer to version 6 (I was previously using v5) and now the animation errors are occurring on desktop as well. 2014年2月10日(更新)-在提供的JSFiddle示例中,我将jwplayer更新为版本6(我以前使用的是v5),现在台式机上也出现了动画错误。 The errors are specifically a result of animations carried on in the leftVideoPriority() and rightVideoPriority() functions. 这些错误具体是在leftVideoPriority()rightVideoPriority()函数中进行动画处理的结果。 This can be confirmed by commenting out calls to those functions in the stop property of the draggable object. 这可以通过在可拖动对象的stop属性中注释掉对这些函数的调用来确认。 On another note, using CSS animations rather than jQuery animations may be a solution to this problem, but it may eliminate support for IE9 and definitely IE8. 另一方面,使用CSS动画而不是jQuery动画可能是解决此问题的方法,但它可能会取消对IE9和IE8的支持。 This is (unfortunately) not acceptable for my purposes. 对于我的目的,这是(不幸的)不可接受的。

I am trying to develop an animating dual-video "widget," if you will, that allows users on both desktop and tablet devices to interact with the widget. 我正在尝试开发一种动画的双视频“窗口小部件”,如果允许的话,它允许台式机和平板电脑设备上的用户与小部件进行交互。 It contains two videos, placed side by side, and separated by a "control bar". 它包含两个视频,并排放置,并由“控制栏”分隔。 That control bar can be dragged along the x-axis to bring either the left or right video into focus. 可以沿x轴拖动该控制栏,以使左右视频成为焦点。 Additionally, either video can be clicked/tapped to toggle it into focus. 此外,可以单击/点击任一视频以将其切换为焦点。 Please view the example to see exactly how it works. 请查看示例以查看其工作原理。

This widget utilizes jwplayer, jQuery UI, & jquery UI touch (a plugin that binds touch events to the mouse event listeners defined in my code). 此小部件利用jwplayer,jQuery UI和jquery UI touch(将触摸事件绑定到我的代码中定义的鼠标事件侦听器的插件)。

The widget works correctly on desktop using Chrome (I have not carried out cross-browser compatibility testing just yet), but there are some errors that happen as a result of the event interaction/animation on tablet devices (specifically iOS and Android). 该小部件可以在使用Chrome的台式机上正常运行(我尚未进行跨浏览器兼容性测试),但是由于平板电脑设备(特别是iOS和Android)上的事件交互/动画,会发生一些错误。 The errors (they appear to be more like quirky css than "errors" per se) are similar on both iOS and Android but differ in that on iOS the error disappears when the animation stops; 错误(它们看起来更像是古怪的css,而不是“错误”本身)在iOS和Android上都相似,但不同之处在于,iOS上的错误在动画停止时消失了; on Android the error sticks after the animation is done. 在Android上,动画制作完成后错误仍然存​​在。

The problem also seems to stem from jwplayer, as removing the code blocks associated with it resolve the animation errors on tablets. 该问题似乎也源于jwplayer,因为删除与其关联的代码块可以解决平板电脑上的动画错误。

Here is an excerpt from my jQuery UI code that executes animations on "draggable" events: 这是我的jQuery UI代码的摘录,该代码在“可拖动”事件上执行动画:

$("#centerBar").draggable({
        axis: "x",
        containment: "#centerBarContainer",
        scroll: false,
        drag: function (event, ui) {

            centerOfHandleFromLeft = ui.offset.left + 25; //get distance from left edge of document to the handle's center

            centerBarPosDelta = centerOfHandleFromLeft - initialHandleFromLeft; // calculate change in center bar position

            // adjust width of video containers according to center bar movement
            $("#videoContainerLeft, #videoContentLeft_wrapper").css({
                "width": centerBarPosDelta + initialLeftVideoWidth
            });
            $('#videoContainerRight, #videoContentRight_wrapper').css({
                "width": initialRightVideoWidth - centerBarPosDelta
            });
        },
        stop: function (event, ui) {

            // check if change in center bar position is more/less than half the width of its draggable area
            if (centerBarPosDelta <= (barContainerWidth / 2)) {
                rightVideoPriority();
            } else {
                leftVideoPriority();
            }
        }
    });

And here are the animation code blocks: 这是动画代码块:

function leftVideoPriority() {
        $('#videoContainerLeft, #videoContentLeft_wrapper, #videoContentLeft').stop().animate({
            "width": 580
        }, 750);
        $('#videoContainerRight, #videoContentRight_wrapper, #videoContentLeft').stop().animate({
            "width": 220
        }, 750);
        $('#centerBar').stop().animate({
            "left": 360
        }, 750);

        currentVideo = 'left';
        enableVideoSound();
    }

    function rightVideoPriority() {
        $('#videoContainerRight, #videoContentRight_wrapper, #videoContentRight').stop().animate({
            "width": 580
        }, 750);
        $('#videoContainerLeft, #videoContentLeft_wrapper, #videoContentLeft').stop().animate({
            "width": 220
        }, 750);
        $('#centerBar').stop().animate({
            "left": 0
        }, 750);

        currentVideo = 'right';
        enableVideoSound();
    }

    function enableVideoSound() {
        if (currentVideo == 'left') {
            jwplayer('videoContentLeft').setVolume(60);
            jwplayer('videoContentRight').setVolume(0);
        } else {
            jwplayer('videoContentRight').setVolume(60);
            jwplayer('videoContentLeft').setVolume(0);
        }
    }

In conclusion, I have tried several variants of jQuery UI touch - jquery ui touch punch, for example - but the animation error persists. 总之,我尝试了jQuery UI touch的几种变体- 例如,jquery ui touchpunch-但动画错误仍然存​​在。 I am satisfied with the tablet event listener functionality, it's just the animation errors that need to be changed. 我对平板电脑事件监听器功能感到满意,只是需要更改的动画错误。 Unfortunately, I have no idea what could be causing them as I am not familiar with tablet/mobile development, and the visible errors do not seem to closely reflect any html element in the DOM (perhaps it is related to #centerBarContainer, as it appears similar in size/positioning, but the visible errors seems to move in a way that #centerBarContainer does not). 不幸的是,我不知道是什么原因导致的,因为我对平板电脑/移动设备开发不熟悉,可见的错误似乎并未紧密反映DOM中的任何html元素(可能与#centerBarContainer有关,因为它看起来像在大小/位置上相似,但可见的错误似乎以#centerBarContainer没有的方式移动。

/edit/ - please excuse any messiness / lack of optimization in my code... I had to strip this down to the version you see here from a more complete version, and some lines of code may not make sense out of that context. / edit /-请原谅我的代码中有任何混乱/缺乏优化的地方...我不得不将其从更完整的版本中简化为您在此处看到的版本,并且某些代码行可能在该上下文之外没有任何意义。 Everything that is pertinent to this issue has been included, however. 但是,与该问题有关的所有内容均已包括在内。

Eureka! 找到了! Before I explain the solution, please understand that I originally used jwplayer v5 for this project, but updated to v6 per Ethan JWPlayer's recommendation. 在解释解决方案之前,请了解我最初是在该项目中使用jwplayer v5,但根据Ethan JWPlayer的建议已更新为v6。 This change resulted in a different structure of jwplayer within the DOM. 此更改导致DOM中jwplayer的结构不同。 Due to the change, I had to tweak the animation functions to apply to the newly correct elements; 由于更改,我不得不调整动画功能以应用于新的正确元素。 doing this led me to accidentally find a solution to the animation errors on both tablet and desktop. 这样做导致我意外地找到了解决平板电脑和台式机动画错误的方法。

Originally, the animation function looked like this: 最初,动画功能如下所示:

function leftVideoPriority() {
        $('#videoContainerLeft, #videoContentLeft_wrapper, #videoContentLeft').stop().animate({
            "width": 580
        }, 750);
        $('#videoContainerRight, #videoContentRight_wrapper, #videoContentRight').stop().animate({
            "width": 220
        }, 750);
        $('#centerBar').stop().animate({
            "left":360
        }, 750);

        currentVideo = 'left';
        enableVideoSound();
    }

The jQuery objects that were calling the animate() method were changed to: 调用animate()方法的jQuery对象已更改为:

$('#videoContainerLeft').animate({...});
$('#videoContainerRight').animate({...});

For v6, one additional change was needed: .jwmain { width:600px; } 对于v6,还需要进行其他更改: .jwmain { width:600px; } .jwmain { width:600px; } in the css .jwmain { width:600px; }在CSS

Removing the unnecessary animation on additional elements seems to have corrected the errors. 删除其他元素上不必要的动画似乎已纠正了这些错误。 I can't claim to understand why they caused the errors to occur in the first place, however. 但是,我不能声称理解为什么它们首先导致了错误。

This change solved the error for both jwplayer v6 & also worked with v5 by also including #videoContentLeft_wrapper and its equivalent #videoContentRight_wrapper in the animated jQuery objects. 此更改解决了jwplayer v6的错误,并且还通过在动画jQuery对象中包含#videoContentLeft_wrapper及其等效的#videoContentRight_wrapper来与v5一起使用。 In both cases, #videoContentLeft and #videoContentRight were removed to correct the animation errors. 在这两种情况下,都删除了#videoContentLeft#videoContentRight来纠正动画错误。

Here is the working version (with code) and another version (without code, for tablet testing) - I will update the original post's jsfiddle examples to show the error as it originally existed. 这是工作版本(带代码)另一个版本(无代码,用于平板电脑测试) -我将更新原始文章的jsfiddle示例,以显示错误的来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM