更改视频后如何强制Clappr播放器保持全屏显示?
我编写了一个在PLAYER_ENDED事件上触发的函数,该函数使用此load
方法加载下一个视频:
enter code here`enter code here`player.load([{source: 'video_url_exmpl'}], null, true);
但是当事件被触发并且新的视频加载播放器取消全屏模式时。我设置选项:
exitFullscreenOnEnd: false,
我编写了一个插件,假设该插件可以切换全屏,但浏览器会发出警告消息:
Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture
这是我的Clappr播放器的初始化和设置:
player = new Clappr.Player({
source: sourceUrl,
parentId: "#player",
autoPlay: true,
width: '100%',
height: '100%',
exitFullscreenOnEnd: false,
playInline: true,
recycleVideo: Clappr.Browser.isMobile,
poster: '',
}).on(Clappr.Events.PLAYER_ENDED, function() {
player.load([{source: 'video_url'}], null, true);
}
});
最佳答案
在官方的Clappr GitHub Issues中找到了临时解决方案。感谢kslimani。
var player = new Clappr.Player({
parentId: "#player-wrapper",
source: 'http://clappr.io/highline.mp4',
height: 360,
width: 640,
exitFullscreenOnEnd: false,
playback: {
playInline: true,
recycleVideo: true,
},
events: {
onEnded: function () {
var setSource = function (newSrc) {
this.core.options.source = newSrc;
var container = this.core.getCurrentContainer();
var playback = this.core.getCurrentPlayback();
if (container) {
container.options.source = newSrc;
}
if (playback) {
playback.options.source = newSrc;
playback._setupSrc && playback._setupSrc(newSrc);
}
}.bind(this);
// Set another .mp4 source and start again player
setSource('https://static.playmedia-cdn.net/resources/sample/h264_sintel_trailer-1080p.mp4');
this.play();
}
}
});
请注意,这段代码很丑陋,可能会使某些播放器组件(如插件)处于不一致状态。仅当源采用相同格式(即:所有源均为.mp4文件)时,此方法才有效。
但是应该给您一些提示,从哪里开始挖掘。
Link on Clappr GitHub threat
关于javascript - 全屏不适用于clappr播放器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45118638/