经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
Ueditor 关于视频上传相关问题
来源:cnblogs  作者:吃剩的方便面  时间:2019/11/13 13:11:07  对本文有异议

 

  !!!每次改动后记得,清除一下浏览器缓存再试 !!!  

 

4点:

1.修复编辑时视频不能预览问题;

2.插入视频的时候。在预览的窗口提示 “输入的视频地址有误,请检查后再试!”

3.ueditor 解决上传视频回显 src链接丢失问题

4.ueditor 自定义插入视频封面(页面加载时显示)

1. 修复编辑视频不能预览问题 

ueditor.all.js 中 ,搜索   me.fireEvent('beforesetcontent', html);

将下列注释

  1. //修复编辑是视频不能预览问题
  2. // me.fireEvent('beforesetcontent', html);
  3. // var root = UE.htmlparser(html);
  4. // me.filterInputRule(root);
  5. // html = root.toHtml();

搜索 me.commands["insertvideo"]  

  1. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));

改成

  1. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'video'));

2. 插入视频的时候。在预览的窗口提示 “输入的视频地址有误,请检查后再试!”如:

解决方法:

1.ueditor.all.js中 搜索   me.commands["insertvideo"]  

//此处 edui-faked-video 改为 edui-faked,防止后面将此处替换为image标签

// 此处将image改为embed/video  ,实现  1.实时预览视频,  2.修复了第一次插入视频保存后,刷新后再保存会导致视频丢失的bug

 

  1. me.commands["insertvideo"] = {
  2. execCommand: function (cmd, videoObjs, type){
  3. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  4. var html = [],id = 'tmpVedio', cl;
  5. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  6. vi = videoObjs[i];
  7. //cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked-video');
  8. //html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));
  9.  
  10. //此处将 edui-faked-video 改为 edui-faked,防止后面将此处替换为image标签
  11. cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked');
  12. // 此处将image改为embed/video , 实现实时预览视频,且修复了第一次插入视频保存后,刷新后再保存会导致视频丢失的bug
  13. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'video'));
  14. }
  15. me.execCommand("inserthtml",html.join(""),true);
  16. var rng = this.selection.getRange();
  17. ...

 

2.ueditor.config.js中 搜索 whitList  

img 字段中 添加"_url"

  1. img:['src', 'alt', 'title', 'width', 'height', 'id', '_src','_url', 'loadingclass', 'class', 'data-latex', 'style', 'url'],//加了style和url

 video 后面添加如下规则字段video不要忘记加逗号

  1. source: ['src', 'type'],
  2. embed: ['type', 'class', 'pluginspage', 'src', 'width', 'height', 'align', 'style', 'wmode', 'play','autoplay','loop', 'menu', 'allowscriptaccess', 'allowfullscreen', 'controls', 'preload'],
  3. iframe: ['src', 'class', 'height', 'width', 'max-width', 'max-height', 'align', 'frameborder', 'allowfullscreen']  

3.dialogs/video/video.js   搜索 function createPreviewVideo(url){     把下面的内容替换 

  1. function createPreviewVideo(url){
  2. if ( !url )return;
  3. var conUrl = convert_url(url);
  4. conUrl = utils.unhtmlForUrl(conUrl);
  5. $G("preview").innerHTML =
  6. // '<div class="previewMsg"><span>'+lang.urlError+'</span></div>'+
  7.   // '<embed class="previewVideo" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  8.    // ' src="' + conUrl + '"' +
  9.   // ' width="' + 420 + '"' +
  10.   // ' height="' + 280 + '"' +
  11.   // ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >' +
  12.   // '</embed>';
  13.  
  14.   //换成video标签
  15. '<video' +
  16. ' src="' + conUrl + '"' +
  17. ' width="' + 420 + '"' +
  18. ' height="' + 280 + '"' +
  19. ' autoplay' +
  20. ' controls="controls">'+
  21. '</video>';
  22. }

3. ueditor 解决上传视频回显 src链接丢失问题

切换 html 按钮src链接丢失问题

ueditor.config.js文件的 361行左右  ,

inputXssFilter:true 修改为 ,inputXssFilter:false

  1.      // xss 过滤是否开启,inserthtml等操作
  2. ,xssFilterRules: true
  3. //input xss过滤
  4. //,inputXssFilter: true
  5. ,inputXssFilter: false //解决视频回显src消失
  6. //output xss过滤
  7. ,outputXssFilter: true
  8. // xss过滤白名单 名单来源: https://raw.githubusercontent.com/leizongmin/js-xss/master/lib/default.js
  9. ,whitList: {
    ...

ueditor.all.js 中  搜索 编辑器默认的过滤转换机制 or UE.plugins['defaultfilter']

 加上return

  1. // plugins/defaultfilter.js
  2. ///import core
  3. ///plugin 编辑器默认的过滤转换机制
  4. UE.plugins['defaultfilter'] = function () {
  5. return;
  6. var me = this;
  7. me.setOpt({
  8. ...

找到  case 'img':  ,注释代码

  1. case 'img':
  2. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  3. // if (val = node.getAttr('src')) {
  4. // if (/^data:/.test(val)) {
  5. // node.parentNode.removeChild(node);
  6. // break;
  7. // }
  8. // }
  9. // node.setAttr('_src', node.getAttr('src'));
  10. break;
  11. ...

4. ueditor 自定义插入视频封面(页面加载时显示)

预先保存一张封面到服务器   假设路径为  /static/images/video-poster.png

ueditor.config.js 中  搜索   whitList   在 video 字段 添加 poster

  1. video: ['autoplay', '_src', 'poster', 'controls', 'loop', 'preload', 'src', 'height', 'width', 'class', 'style', 'id'],

修改ueditor.all.js中 搜索    case 'video':    添加 poster  字段 (通过js获取当前域名,拼接上保存到服务器上的图片作为url)

  1.    case 'embed':
  2. //str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  3. str = '<embed class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  4. ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
  5. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  6. break;
  7. case 'video':
  8. var ext = url.substr(url.lastIndexOf('.') + 1);
  9. //当前域名window.location.protocol+"//"+window.location.host
  10. var locationHost = window.location.protocol+"//"+window.location.host;
  11. if(ext == 'ogv') ext = 'ogg';
  12. str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
  13. ' controls preload="none" width="' + width + '" height="' + height +
  14. '" poster="'+locationHost+'/static/images/video-poster.png" src="' + url + '" data-setup="{}">' +
  15. '<source src="' + url + '" type="video/' + ext + '" /></video>';
  16. break;

原文链接:http://www.cnblogs.com/wuhuanan/p/11766844.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号