gpt4 book ai didi

javascript - 触摸设备中的 VideoJS 播放器覆盖按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:02 26 4
gpt4 key购买 nike

我使用的是VideoJs player 4.2

当我在 ios 设备的 safari 浏览器中打开 videojs 播放器时,它默认在 native 控件上运行。当我暂停播放器时,我会在视频上显示叠加按钮(指向其他页面的链接)。如果我单击按钮,它不会在 ios 中触发。它在桌面浏览器中运行良好。如果我将 nativeControlsForTouch 设置为 false,它会显示自定义控件。这里覆盖按钮和自定义控件有效,但它会很慢,我无法滚动视频,与 native 控件相比,它会不流畅。请给我任何想法

  1. 如果我使用 native 控件,则覆盖按钮必须有效
  2. 如果我使用自定义控件,那么与原生控件相比,视频播放器将一样流畅

这是我的代码

videojs("ex_video",{"controls":true, "preload":"metadata","width":"auto", "height":"auto",
"poster":"/images/test.png"},function(){
var current_player=this;
current_player.imageOverlay({
opacity: 0.5,
height: '100%',
width: '50%'
});
current_player.on("pause", function(){
current_player.bigPlayButton.show();

});
current_player.on("play", function(){
current_player.bigPlayButton.hide();
});
});

叠加按钮代码

(function(vjs) {
var
extend = function(obj) {
var arg, i, k;
for (i = 1; i < arguments.length; i++) {
arg = arguments[i];
for (k in arg) {
if (arg.hasOwnProperty(k)) {
obj[k] = arg[k];
}
}
}
return obj;
},

defaults = {
image_url: '',
click_url: '',
start_time: null,
end_time: null,
opacity: 0.7,
height: '15%',
width: '100%'
},

imageOverlay = function(options) {

var player = this,
settings = extend({}, defaults, options || {}),
showingImage = false;

if (settings.start_time === null)
settings.start_time = 0;

if (settings.end_time === null)
settings.end_time = player.duration() + 1;

overlay = {

showImage: function() {
if (showingImage) {

return;
}
showingImage = true;
var holderDiv = document.createElement('div');
holderDiv.id = 'vjs-image-overlay-holder';
holderDiv.style.height = settings.height;
holderDiv.style.width = settings.width;
holderDiv.style.opacity=settings.opacity;

var overlayLbl1= document.createElement('label');
overlayLbl1.setAttribute('class','heading-overlay-video');
overlayLbl1.innerHTML= "Like this class? Why not:";
var topVideoP=overlay.createEl(overlayLbl1);
topVideoP.className=topVideoP.className+' top-video-control-overlay';
holderDiv.appendChild(topVideoP);

//Save to queue
var overlayBtn1=document.createElement('button');
overlayBtn1.value = 'Save to queue';
overlayBtn1.innerHTML='Save to queue';
overlayBtn1.setAttribute('class','white medium');
holderDiv.appendChild(overlay.createEl(overlayBtn1));

//Add to series button
var overlayBtn2=document.createElement('button');
overlayBtn2.value = 'Add to series';
overlayBtn2.innerHTML='Add to series';
overlayBtn2.setAttribute('class','white medium');
holderDiv.appendChild(overlay.createEl(overlayBtn2));

var overlayLbl2= document.createElement('label');
overlayLbl2.innerHTML= "music credits";
overlayLbl2.setAttribute('class','msg-blue');
var btmVideoP=overlay.createEl(overlayLbl2);
btmVideoP.className=btmVideoP.className+' bottom-video-control';
holderDiv.appendChild(btmVideoP);



player.el().appendChild(holderDiv);
},
hideImage: function() {
if (!showingImage) {
return;
}
showingImage = false;
player.el().removeChild(document.getElementById('vjs-image-overlay-holder'));
},
createEl:function(ele_obj){
var overlayP=document.createElement('p');
overlayP.setAttribute('class','overlay-video-content-in');
overlayP.appendChild(ele_obj);
return overlayP ;
}
};
var setTimeoutControl;

player.on('pause', function(){
setTimeoutControl= setTimeout(function(){overlay.showImage()},5000);

});
player.on('play', function(){
clearTimeout(setTimeoutControl);
overlay.hideImage();
});
};
vjs.plugin('imageOverlay', imageOverlay);
}(window.videojs));

最佳答案

默认情况下,浏览器中的 HTML5 视频将在 iPod、iPhone 的 native 播放器中打开。您必须将 HTML 内容包装在 webview 中并像本地应用程序一样运行它才能在 iPod、Iphone 中查看视频。

查看此 HTML5 inline video on iPhone vs iPad/Browser

所以这两个改动必须在HTML中完成

<video id="xxx" width="xx" height="xx" webkit-playsinline>

objective-C

webview.allowsInlineMediaPlayback = YES;

在所有其他设备中,没有这些也可以正常工作

关于javascript - 触摸设备中的 VideoJS 播放器覆盖按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com