星联网络专注帝国CMS二次功能插件开发-精品网站模板站长代码素材

  • 最近更新
  • 模板:33
  • 记录:12641|
  • 插件:52|
  • 工具:4|
  • 代码:8|
  • 评论:0

织梦百度小程序微信小程序video标签不支持视频封面,autoplay等问题修复方法

前言

本文主要讲解《织梦百度小程序微信小程序video标签不支持视频封面,auoplay等问题修复方法》的详细内容

在现有的百度小程序富文本组件bdParse,以及微信小程序富文本组件wxParse,对于video的标签解析仅仅只是有个video而已,其他的属性几乎都过滤掉了,所以就需要我们假设对于属性(由于H5的video属性和小程序的video属性要求不一样,以小程序为主)

一、百度小程序的bdParse修复方法

(1)打开bdParse/bdParse.swan找到video标签解析处大致第10行:

<template name="bdParseVideo"> 
  <!--增加video标签支持,并循环添加--> 
  <view class="{{item.classStr}} bdParse-{{item.tag}}" style="{{item.styleStr}}"> 
    <video class="{{item.classStr}} bdParse-{{item.tag}}-video" src="{{item.attr.src}}"></video> 
  </view> 
</template>

改成:

<template name="bdParseVideo"> 
  <!--增加video标签支持,并循环添加--> 
  <view class="{{item.classStr}} bdParse-{{item.tag}}" style="{{item.styleStr}}"> 
    <video class="{{item.classStr}} bdParse-{{item.tag}}-video" poster="{{item.attr.poster}}" autoplay="{{item.attr.autoplay}}" controls="{{item.attr.controls}}" loop="{{item.attr.loop}}" muted="{{item.attr.muted}}" src="{{item.attr.src}}"></video> 
  </view> 
</template>

(2)针对dedecms用户以及其它video的poster属性不显示全网址的修复办法

在小程序的内容之前使用正则替换,补全poster地址:

dede版百度小程序demo修复:show.js的113行加入以下代码:

content.body = content.body.replace(/poster=\"(.*)\"/gi, 'poster=\"'+ app.globalData.host+'$1\"');


二、微信小程序wxParse修复方法

(1)打开wxParse/wxParse.wxml找到video标签解析处大致第13行:

<template name="wxParseVideo"> 
  <!--增加video标签支持,并循环添加--> 
  <view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}"> 
    <video class="{{item.classStr}} wxParse-{{item.tag}}-video" src="{{item.attr.src}}"></video> 
  </view> 
</template>

改成:

<template name="wxParseVideo"> 
  <!--增加video标签支持,并循环添加--> 
  <view class="{{item.classStr}} wxParse-{{item.tag}}" style="{{item.styleStr}}"> 
    <video class="{{item.classStr}} wxParse-{{item.tag}}-video" poster="{{item.attr.poster}}" autoplay="{{item.attr.autoplay}}" controls="{{item.attr.controls}}" loop="{{item.attr.loop}}" muted="{{item.attr.muted}}"  src="{{item.attr.src}}"></video> 
  </view> 
</template>

(2)同理需要对文章中的poster不是全网址的视频封面图片补全网址

dede版微信小程序demo修复:show.js的105行加入以下代码:

content.body = content.body.replace(/poster=\"(.*)\"/gi, 'poster=\"' + app.globalData.host + '$1\"');


【注意】

小程序的video和H5的video稍微有点不同

autoplay、controls、loop、muted等属性需要写成:autoplay=“{{true}}”,controls=“{{true}}”

这样就可以实现了h5的video标签的常用属性,如图:

织梦百度小程序微信小程序video标签不支持视频封面,autoplay等问题修复方法

本网刊登的文章均仅代表作者个人观点,并不代表本网立场。文中的论述和观点,敬请读者注意判断。

本文地址:http://www.xlkjgs.com/notes/web/8773.html

以上内容由本站整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

星联网络

星联网络是中国最具实战的互联网创业者的知识服务商,这里有互联网行业动态,网络推广,SEO优化,SEM优化,ESC配置,行业经验分型,互联网项目,微信营销、淘宝客赚钱、新媒体营销、京东运营、跨境电商等众多互联网营销知识分享

站长运营站长必备网站运营之道才能长久发展