最近播放器变动较大,换了速度较快的资源站,对应之前资源站的播放地址再打开时播放列表就会显示空白,大概率会导致用户流失。

播放地址(如 111100-3-1.html)的生成与播放器编码(sid
参数,此处3
对应原 aaa 播放器的编码)相关。当播放器被删除后,可通过检测sid
对应的播放器是否存在,若不存在则触发跳转。
播放页请求由index/vod/play
控制器处理,需在该控制器的播放逻辑中添加判断。控制器文件为application/index/controller/Vod.php
,找到play部分:
原始代码:
public function play()
{
$info = $this->label_vod_play('play');
if($info['vod_copyright']==1 && $GLOBALS['config']['app']['copyright_status']==3){
return $this->label_fetch('vod/copyright');
}
return $this->label_fetch( mac_tpl_fetch('vod',$info['vod_tpl_play'],'play') );
}
优化之后的代码:
public function play()
{
$info = $this->label_vod_play('play');
// 获取当前请求的播放器编码(sid参数)
$param = mac_param_url();
$sid = $param['sid'] ?? 0;
// 获取系统中已配置的播放器列表
$vodPlayers = config('vodplayer');
$playerExists = false;
// 检查当前sid对应的播放器是否存在
if (!empty($info['vod_play_list'][$sid]['from'])) {
$playerFrom = $info['vod_play_list'][$sid]['from'];
$playerExists = isset($vodPlayers[$playerFrom]) && $vodPlayers[$playerFrom]['status'] == 1;
}
// 若播放器不存在,跳转到视频详情页
if (!$playerExists) {
$detailUrl = mac_url_vod_detail($info);
$this->redirect($detailUrl);
return;
}
// 原有版权检测逻辑
if($info['vod_copyright']==1 && $GLOBALS['config']['app']['copyright_status']==3){
return $this->label_fetch('vod/copyright');
}
return $this->label_fetch( mac_tpl_fetch('vod',$info['vod_tpl_play'],'play') );
}
这样修改以后访问一个已删除播放器地址时就会自动跳转到详情页。