LibreTV
LibreTV copied to clipboard
能不能把播放器做成能自定义跳过片头和片尾
Confirm / 确认
- [x] I have searched the Issue and found no related feature requests / 我已经搜索过Issue,没有找到相关的功能请求
Feature Description / 功能描述
播放界面能不能做成能自定义跳过片头和片尾时间,像TVBOX的播放器一样有可以选择IJK或EXO两种播放器二种选择可以选择IJK或EXO两种播放器
How to Implement / 如何实现
No response
Additional Information / 附加信息
No response
IJKPlayer 是一款功能强大的开源跨平台视频播放器框架 跨平台方案:需通过以下方式桥接Web与原生能力: WebView嵌入:将IJKPlayer封装为原生组件,通过WebView与网页交互。 协议转换:将RTMP/HTTP-FLV等流转换为HLS/WebRTC等Web兼容格式
功能说明:
设置菜单:
- 在播放器设置中添加三个新选项
-
全局开关:启用/禁用跳过功能
-
片头时长:设置片头持续时间(秒)
-
片尾时长:设置片尾持续时间(秒)
控制栏按钮:
- 添加两个新按钮到控制栏右侧:
-
跳过片头按钮:点击后跳过当前片头
-
跳过片尾按钮:点击后直接播放下一集
自动跳过逻辑:
-
片头自动跳过:播放进入片头区域时自动跳到片头结束位置
-
片尾自动跳过:播放进入片尾区域时自动跳到下一集
-
智能显示:只有需要时才会显示跳过按钮
本地存储:
-
所有设置都保存在localStorage中
-
下次访问时会记住用户的设置
视觉反馈:
-
自动跳过时显示倒计时提示
-
按钮悬停时显示功能提示
代码 把这段代码中的片段添加到你克隆仓库的js/player.js中相应位置即可。
// 在全局变量部分添加
let skipIntroDuration = 90; // 默认跳过90秒片头
let skipEndingDuration = 90; // 默认跳过90秒片尾
let skipEnabled = true; // 是否启用跳过功能
let skipIntroButton = null; // 跳过片头按钮实例
let skipEndingButton = null; // 跳过片尾按钮实例
// 在initializePageContent函数中添加
// 从本地存储加载跳过设置
skipEnabled = localStorage.getItem('skipEnabled') !== 'false';
skipIntroDuration = parseInt(localStorage.getItem('skipIntroDuration')) || 90;
skipEndingDuration = parseInt(localStorage.getItem('skipEndingDuration')) || 90;
// 修改ArtPlayer配置
art = new Artplayer({
// ...其他配置保持不变...
settings: [
// 添加跳过功能设置
{
html: '跳过片头片尾',
tooltip: skipEnabled ? '开' : '关',
switch: skipEnabled,
onSwitch: function (item) {
skipEnabled = !skipEnabled;
item.switch = skipEnabled;
item.tooltip = skipEnabled ? '开' : '关';
localStorage.setItem('skipEnabled', skipEnabled);
return true;
},
},
{
html: '片头时长(秒)',
tooltip: skipIntroDuration,
onInput: function (item, event) {
const value = parseInt(event.target.value);
if (!isNaN(value)) {
skipIntroDuration = value;
item.tooltip = value;
localStorage.setItem('skipIntroDuration', value);
}
},
},
{
html: '片尾时长(秒)',
tooltip: skipEndingDuration,
onInput: function (item, event) {
const value = parseInt(event.target.value);
if (!isNaN(value)) {
skipEndingDuration = value;
item.tooltip = value;
localStorage.setItem('skipEndingDuration', value);
}
},
},
// 其他设置项...
],
});
// 在播放器初始化后添加跳过按钮
art.on('ready', () => {
// 创建跳过片头按钮
skipIntroButton = art.controls.add({
position: 'right',
html: '<svg width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M8,5.14V19.14L19,12.14L8,5.14Z"/></svg>',
tooltip: '跳过片头',
style: {padding: '0 10px'},
click: function () {
if (art && art.video) {
art.currentTime = Math.min(art.currentTime + skipIntroDuration, art.duration - 1);
}
}
});
// 创建跳过片尾按钮
skipEndingButton = art.controls.add({
position: 'right',
html: '<svg width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M6,18L14.5,12L6,6V18ZM16,6V18H18V6H16Z"/></svg>',
tooltip: '跳过片尾',
style: {padding: '0 10px'},
click: function () {
if (art && art.video && autoplayEnabled && currentEpisodeIndex < currentEpisodes.length - 1) {
playNextEpisode();
}
}
});
});
// 在timeupdate事件中添加自动跳过逻辑
art.on('video:timeupdate', function() {
const currentTime = art.currentTime;
const duration = art.duration;
// 自动跳过片头
if (skipEnabled && currentTime < skipIntroDuration) {
// 显示提示(只在片头区间显示)
if (currentTime > 5 && currentTime < skipIntroDuration - 5) {
art.notice.show(`自动跳过片头 (${Math.floor(skipIntroDuration - currentTime)}秒)`);
}
art.currentTime = skipIntroDuration;
}
// 自动跳过片尾(提前5秒触发)
if (skipEnabled && duration > 0 && autoplayEnabled &&
currentTime > duration - skipEndingDuration &&
currentTime < duration - 5 &&
!videoHasEnded &&
currentEpisodeIndex < currentEpisodes.length - 1) {
art.notice.show(`自动跳过片尾,播放下一集`);
playNextEpisode();
}
// 控制跳过按钮的可见性
if (skipIntroButton) {
skipIntroButton.$el.style.display = (currentTime > 10 && currentTime < duration - skipIntroDuration - 30) ? 'block' : 'none';
}
if (skipEndingButton) {
const showEndingButton = autoplayEnabled &&
currentTime > duration - skipEndingDuration - 30 &&
currentTime < duration - 10 &&
currentEpisodeIndex < currentEpisodes.length - 1;
skipEndingButton.$el.style.display = showEndingButton ? 'block' : 'none';
}
});
// 在播放结束时隐藏跳过按钮
art.on('video:ended', function () {
if (skipIntroButton) skipIntroButton.$el.style.display = 'none';
if (skipEndingButton) skipEndingButton.$el.style.display = 'none';
});
谢谢了