wordpress在线播放php插件,让WordPress视频播放插件Smartideo支持B站BV号
打開Smartideo插件smartideo.php文件,在大約87行:array($this, 'smartideo_embed_handler_bilibili') );
下面添加:wp_embed_register_handler( 'smartvideo_bilibili_bv',
'#https?://www\.bilibili\.com/video/BV(?:(?[a-z0-9_=\-]+)/(?:index_|\#page=)(?[a-z0-9_=\-]+)|(?[a-z0-9_=\-]+))#i',
array($this, 'smartvideo_embed_handler_bilibili_bv') );
接下來在大約195行找到:return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
在其下面“}”大括號下面添加:public function smartvideo_embed_handler_bilibili_bv( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
$page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
$cid = '';
$embed = $this->get_iframe("//player.bilibili.com/player.html?bvid=BV{$matches['video_id']}&cid={$cid}&page={$page}", $url);
return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}
之后直接在文章中添加B站視頻地址:https://www.bilibili.com/video/BV1WW411b7NQ
試試吧,可以加載播放視頻了。
不過發現插件貌似也不支原來的av地址呢,難道在高級功能里?沒試過。https://www.bilibili.com/video/av17792443
再接著修改一下吧,將:public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
$page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
$cid = '';
/*
try{
$request = new WP_Http();
$url = "https://api.bilibili.com/view?type=jsonp&appkey=8e9fc618fbd41e28&id=" . $matches['video_id'];
$data = (array)$request->request($url, array('timeout' => 3));
$json = json_decode($data['body'], true);
$cid = $json['cid'];
}catch(Exception $e){}
*/
if(wp_is_mobile() || $this->bilibili_pc_player == 1){
$embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url);
}else{
$embed = $this->get_link($url);
}
return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}
直接改為:public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
$page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
$cid = '';
$embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$matches['video_id']}&cid={$cid}&page={$page}", $url);
return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}
總結
以上是生活随笔為你收集整理的wordpress在线播放php插件,让WordPress视频播放插件Smartideo支持B站BV号的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qos限速、流量监管、流量整形原理和实验
- 下一篇: 电脑截图全屏