民审-M

如何让discuz x3.3 x3.2论坛手机版也能播放网络视频?

作者:民审-M   发布时间:2017-07-05 11:40   回复数:0   浏览数:5677
民审-M
56770民审-M金牌草根
2017-07-05 11:40:09
56770 2017-07-05 11:40:09
[p=null, 2, left][color=rgb(0, 0, 0)]discuz论坛这么多个版本,有时候部落真是想不通,居然没有一个支持手机版播放在线视频的,正常情况下,我们在手机上打开某个含有视频链接的贴子,显示的都是一行代码,当然,现在已经有插件可以解决这个问题.不过部落当时试了一个,效果也不是很理想,像播放网络视频,也就是外部视频的话,需要支持的东西有点多,最让人不舒服的是,discuz这么多的版本,居然没有一个解析外部视频链接的.[/p][p=null, 2, left][color=rgb(0, 0, 0)]论坛如何发表连接外部视频(例如优酷网的视频)的帖子.[/p][p=null, 2, left][color=rgb(0, 0, 0)]这里部落先简单说一下,可以使用以下两种方法[/p][p=null, 2, left][color=rgb(0, 0, 0)]方法1:[/p][p=null, 2, left][color=rgb(0, 0, 0)]a、后台 => 界面 => 编辑器设置 => Discuz!代码 => Flash栏 勾选 可用[/p][p=null, 2, left][color=rgb(0, 0, 0)]b、版块 => 版块名称后编辑 => 帖子选项 => 允许使用 Discuz! 代码: 选择 是[/p][p=null, 2, left][color=rgb(0, 0, 0)]c、用户 => 用户组 => 详情 => 帖子选项 => 设置下允许使用discuz代码[/p][p=null, 2, left][color=rgb(0, 0, 0)]d、发帖时可以选择开启的 Flash 图标,放入优酷等视频网站的 Flash 地址。[/p][p=null, 2, left][color=rgb(0, 0, 0)]方法2:[/p][p=null, 2, left][color=rgb(0, 0, 0)]a、后台 => 界面 => 编辑器设置 => Discuz!代码 => media栏 勾选 可用[/p][p=null, 2, left][color=rgb(0, 0, 0)]b、版块 => 版块名称后编辑 => 帖子选项 => 设置允许使用media代码以及允许使用 Discuz! 代码[/p][p=null, 2, left][color=rgb(0, 0, 0)]c、发帖时可以选择开启的 media 图标,放入优酷等视频网站的 Flash 地址.[/p][p=null, 2, left][color=rgb(0, 0, 0)]通常情况下,我们在贴子中插入一段视频,在手机上打开,显示的是下面的内容:[/p]<embed src=\"http://外部视频链接/player.php/Type/Folder/Fid/22967553/Ob/1/sid/XOTMzODc3MjY0/v.swf\" quality=\"high\" width=\"480\" height=\"400\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"true\" mode=\"transparent\" type=\"application/x-shockwave-flash\"></embed>
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]discuz手机播放视频[/p][p=null, 2, left][color=rgb(0, 0, 0)]部落找到了一个六月_手机视频播放免费版,大家可以试试看,介绍地址是:由此直达.[/p][p=null, 2, left][color=rgb(0, 0, 0)]优酷 土豆 56 酷六视频等视频资源在手机端点击既能及时观看.[/p][p=null, 2, left][color=rgb(0, 0, 0)]当然,还有其它的,自己可以找一下.[/p][p=null, 2, left][color=rgb(0, 0, 0)]如何让discuz论坛手机版也能播放网络视频?[/p][p=null, 2, left][color=rgb(0, 0, 0)]这里部落列出自己收集的几个方法:[/p][p=null, 2, left][color=rgb(0, 0, 0)]一.[/p][p=null, 2, left][color=rgb(0, 0, 0)]如果手机安装了flash播放器,可以使用下面的方法.[/p][p=null, 2, left][color=rgb(0, 0, 0)]首先我们打开source/function/function_discuzcode.php,然后查找:[/p]$message = preg_replace(\"/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is\", \"[media]\\4[/media]\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]修改为:[/p]$message = preg_replace(\"/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/\", \"<embed src='\\4' allowFullScreen='true' quality='high' width='260' height='150' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash'></embed>\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]保存后手机版的discuz 也能播放网络视频了.[/p][p=null, 2, left][color=rgb(0, 0, 0)]部落的线报论坛成功操作后如下图:[/p][p=null, 2, left][color=rgb(0, 0, 0)][/p][p=null, 2, left][color=rgb(0, 0, 0)]二.[/p][p=null, 2, left][color=rgb(0, 0, 0)]另外一种方法实现,在版块里禁用discuz代码,采用html代码!然后在编辑器里用如杲方式调用,这样手机就可以访问了.[/p][p=null, 2, left][color=rgb(0, 0, 0)][/p][p=null, 2, left][color=rgb(0, 0, 0)]论坛板块和用户权限打开html支持,发帖选项,纯文本,html(点开附加选项才可以选html),然后插入以下代码,视频id XNzEwMzEyNDk2 换成自己的,可以在优酷网视频网址里看到.[/p][p=null, 2, left][color=rgb(0, 0, 0)]这个方法部落没有测试,自测吧.[/p][p=null, 2, left][color=rgb(0, 0, 0)]三.[/p][p=null, 2, left][color=rgb(0, 0, 0)]手机版支持播放外链视频的方法,可支持触屏版,也可支持标准版.[/p][p=null, 2, left][color=rgb(0, 0, 0)]首先找到discuz的ubb代码解析文件(source/function/function_discuzcode.PHP),在大约199行的时候可以看到,如果用户打开的是手机版,那么[media]、、[flash=314,256,1]这3个标签都会被放弃解析,统一输出成[media]XXXXX[/media]这种格式.[/p][p=null, 2, left][color=rgb(0, 0, 0)]首先改动[media]标签的解析,将第200行的代码:这个和第一部的基本一样,只是后面加入解析代码.[/p]$message = preg_replace(\"/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/is\", \"[media]\\2[/media]\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]修改为:[/p]$message = preg_replace(\"/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/is\", \"<p class=\\"hm\\" onclick=\\"openVideo(this,'\\2')\\"><img src=\\"static/image/common/vd.gif\\" /></p>\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]在来改动[flash=314,256,1]标签的解析,将205行的代码:[/p]$message = preg_replace(\"/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is\", \"[media]\\4[/media]\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]修改为:[/p]$message = preg_replace(\"/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is\", \"<p class=\\"hm\\" onclick=\\"openVideo(this,'\\4')\\"><img src=\\"static/image/common/vd.gif\\" /></p>\", $message);
[p=null, 2, left][color=rgb(0, 0, 0)]  [/p][p=null, 2, left][color=rgb(0, 0, 0)]然后修改模版文件(template/default/touch/forum/viewthread.htm),在任意一个JS标签中加入解析视频的代码:[/p]function openVideo(a,b) {  
        $(a).html('<img src=\"static/image/mobile/images/icon_load.gif\" />');  
        var w = $(a).width();  
        var h = w * 0.85;  
        if(/youku/.test(b)){ //解析优酷  
                b = b.match(/id_(.*?)\.html|sid\/(.*?)\/v/);  
                b = 'http://player.youku.com/embed/' + (b[1] ? b[1] : b[2]);  
        }else if(/bilibili|acg\.tv/.test(b)){ //解析B站  
                b = b.match(/o\/av(.*?)\/|aid=(.*?)&/);  
                b = 'http://www.bilibili.com/video/av' + (b[1] ? b[1] : b[2]);  
        }else{  
                $(a).html('不支持此视频地址显示:' + b);  
                return;  
        }  
        $(a).append('<iframe width=0 height=0 src=\"' + b + '\" scrolling=no frameborder=0 allowfullscreen></iframe>');  
        $(a).children('iframe').load(function(){  
                $(a).children('img').remove();  
                $(a).children('iframe').css({'width':w,'height':h});  
        })  
}
[p=null, 2, left][color=rgb(0, 0, 0)] [/p][p=null, 2, left][color=rgb(0, 0, 0)]可以用手机打开一个有视频的帖子看看效果了.[/p][p=null, 2, left][color=rgb(0, 0, 0)]这里只写了优酷和B站的解析,其他视频地址的解析暂时没有写,不过有了上面的JS做参考很简单就可以写出支持其他站的视频外链。其原理就是,按照视频URL匹配出VID然后组成可以加载出HTML5播放器的URL在通过iframe框架加载页面就行了.[/p][p=null, 2, left][color=rgb(0, 0, 0)]小结[/p][p=null, 2, left][color=rgb(0, 0, 0)]discuz论坛手机版也能播放网络视频,如果要等官方的支持,估计还得有些时间.部落目前自己使用的就是第一种方法.[/p]
游客
登录后才可以回帖,登录 或者 注册