我的网站上有一个Brightcove视频。我的网站具有响应能力,因此我希望播放器也能响应。现在,我浏览了Brightcove文档中的“视频播放器的响应大小”。这是链接:
http://docs.brightcove.com/en/video-cloud/smart-player-api/samples/responsive-sizing.html

但是,它不适用于我的视频。我还在自己的网站上创建了一个测试页,在该页上我粘贴了他们的示例代码,但是即使失败了。当我在移动设备上打开其示例页面时,一切正常。但是相同的代码在我的网站上失败了。

另外,我怀疑onTemplateLoad和onTemplateReady事件不会触发,因为在窗口调整大小时出现错误消息“ experienceModule is undefined”。

我在下面提供了示例代码:

<style type="text/css">
 .containing-block {
      width: 75%;
     }
    .outer-container {
      position: relative;
      height: 0;
      padding-bottom: 56.25%;
    }
    .BrightcoveExperience {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }</style>
<div class="containing-block" id="container2"><div class="outer-container"    id="container1"><!-- Start of Brightcove Player --><div style="display:none">&nbsp;</div><!--
        By use of this code snippet, I agree to the Brightcove Publisher T and C
        found at https://accounts.brightcove.com/en/terms-and-conditions/.
        -->
<script language="JavaScript" type="text/javascript"    src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>

<script src="http://admin.brightcove.com/js/APIModules_all.js"></script>

<object class="BrightcoveExperience" id="myExperience1754276221001">
<param name="includeAPI" value="true" /><param name="templateLoadHandler" value="onTemplateLoaded" /><param name="templateReadyHandler" value="onTemplateReady" /><param name="bgcolor" value="#FFFFFF" /><param name="width" value="480" /><param name="height" value="270" /><param name="playerID" value="1785957921001" /><param name="playerKey" value="AQ~~,AAABmA9XpXk~,-Kp7jNgisrdzE4WB9lhVzM13pYBWmmbj" /><param name="isVid" value="true" /><param name="isUI" value="true" /><param name="dynamicStreaming" value="true" /><param name="@videoPlayer" value="1754276221001" /></object><script src="//docs.brightcove.com/en/scripts/https-fix.js"></script><script type="text/javascript">brightcove.createExperiences();</script></div></div>


<script type="text/javascript">
    var player,
      APIModules,
      videoPlayer,
      experienceModule;

    function onTemplateLoaded(experienceID){
      console.log("EVENT: onTemplateLoad");
      player = brightcove.api.getExperience(experienceID);
      APIModules = brightcove.api.modules.APIModules;
    }

    function onTemplateReady(evt){
      console.log("EVENT.onTemplateReady");
      videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
      experienceModule = player.getModule(APIModules.EXPERIENCE);
      videoPlayer.play();

      videoPlayer.getCurrentRendition( function (renditionDTO) {

         var newPercentage = ( renditionDTO.frameHeight / renditionDTO.frameWidth ) * 100;
         newPercentage = newPercentage + "%";
         console.log("Video Width = "+renditionDTO.frameWidth+" and Height = "+renditionDTO.frameHeight);
         console.log("New Percentage = "+newPercentage);
         document.getElementById("container1").style.paddingBottom = newPercentage;
      });
 var evt = document.createEvent('UIEvents');
evt.initUIEvent('resize',true,false,0);
window.dispatchEvent(evt);
videoPlayer.play();
    }
 function calulateNewPercentage(width,height) {
logit("function", "calulateNewPercentage");
var newPercentage = ((height / width) * 100) + "%";
logit("Video Width = ", width);
logit("Video Height = ", height);
logit("New Percentage = ", newPercentage);
document.getElementById("container1").style.paddingBottom = newPercentage;
}
 window.onresize = function(evt) {
var $=jQuery;
var resizeWidth = $(".BrightcoveExperience").width(),
resizeHeight = $(".BrightcoveExperience").height();
if (experienceModule.experience.type == "html"){
experienceModule.setSize(resizeWidth, resizeHeight)
//logit("html mode: ", "call setSize method to resize player");
   }
  }

      </script>


我真的很茫然,任何帮助将不胜感激!

最佳答案

我遇到了同样的问题,并使用一些仅在HTML5体验上使用resize事件的Javascript解决了该问题。

foo = (function() {
    var players = []
    return {
        onTemplateLoad: function(id) {
            players.push(id);
    },
        onTemplateReady: function(event) {
            var player = brightcove.api.getExperience(event.target.experience.id);
            var videoPlayer = player.getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER);
            var experienceModule = player.getModule(brightcove.api.modules.APIModules.EXPERIENCE);

            if (experienceModule.experience.type == "html") {
                window.addEventListener("resize", function(event) {
                    for (var i = 0; i < players.length; i++) {
                        var resizeWrapper = $('.js-video-container');
                        var resizeWidth = resizeWrapper.innerWidth();
                        var resizeHeight = resizeWrapper.innerHeight();
                        experienceModule.setSize(resizeWidth, resizeHeight)
                    }
                })
            }
        }
    }
}())

关于javascript - Brightcove视频无法响应移动设备上的方向变化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25221480/

10-10 08:58