小程序开发之组件cover-view、 cover-image(覆盖在原生组件的组件)
cover-view
覆盖在原生组件之上的文本视图,可覆盖的原生组件包括map、video、canvas、camera、live-player、live-pusher,只支持嵌套cover-view、cover-image,可在cover-view中使用button。
cover-image
覆盖在原生组件之上的图片视图,可覆盖的原生组件同cover-view,支持嵌套在cover-view里。
例:在Viedo上加播放暂停按钮和自定义显示时间的文本信息
效果展示:
(1)先找两张播放暂停的图片拖入工程
如:
注:记得开启不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书,否则不支持http无备案域名
(3)代码
index.wxml
<video
class="videoView"
id="myVideo"
src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400"
controls="{{false}}"
>
<cover-view class="controls">
<cover-view class="play" bindtap="play">
<cover-image class="img" src="../image/icon_play.png" />
</cover-view>
<cover-view class="pause" bindtap="pause">
<cover-image class="img" src="../image/icon_pause.png" />
</cover-view>
<cover-view class="time">00:00</cover-view>
</cover-view>
</video>
index.wxss
.videoView{
width: 100%
}
.controls {
position: relative;
top: 50%;
height: 50px;
margin-top: -25px;
display: flex;
}
.play,
.pause,
.time {
flex: 1;
height: 100%;
}
.time {
text-align: center;
background-color: rgba(0, 0, 0, 0.5);
color: white;
line-height: 50px;
}
.img {
width: 40px;
height: 40px;
margin: 5px auto;
}
index.js
Page({
onReady() {
this.videoCtx = wx.createVideoContext('myVideo')
},
play() {
this.videoCtx.play()
},
pause() {
this.videoCtx.pause()
}
})