video
解释:视频
属性说明:
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
src | String | 视频的资源地址 | |
initial-time | Number | 指定视频初始播放位置 | |
duration | Number | 指定视频时长 | |
controls | Boolean | true | 是否显示默认播放控件(播放/暂停按钮、播放进度、时间) |
autoplay | Boolean | false | 是否自动播放 |
loop | Boolean | false | 是否循环播放 |
muted | Boolean | false | 是否静音播放 |
objectFit | String | contain | 当视频大小与 video 容器大小不一致时,视频的表现形式。contain :包含,fill :填充,cover :覆盖 |
poster | String | - | 视频封面的图片网络资源地址 |
page-gesture | Boolean | false | 在非全屏模式下,是否开启使用手势调节亮度与音量。 |
show-progress | Boolean | true | 若不设置,宽度大于240时才会显示。 |
show-fullscreen-btn | Boolean | true | 是否显示全屏按钮 |
enable-progress-gesture | Boolean | true | 是否开启使用手势控制进度 |
danmu-list | Array.<object> | - | 弹幕列表 |
danmu-btn | Boolean | false | 是否显示弹幕按钮,只在初始化时有效,不能动态变更。 |
enable-danmu | Boolean | false | 是否展示弹幕,只在初始化时有效,不能动态变更。 |
show-play-btn | Boolean | true | 是否显示视频底部控制栏的播放按钮 |
show-center-play-btn | Boolean | true | 是否显示视频中间的播放按钮 |
bindpause | EventHandle | 当暂停播放时触发 pause 事件 | |
bindended | EventHandle | 当播放到末尾时触发 ended 事件 | |
bindtimeupdate | EventHandle | 播放进度变化时触发,event.detail = {currentTime, duration} 。 | |
bindfullscreenchange | EventHandle | 当视频进入和退出全屏是触发,event.detail = {fullscreen, direction},direction 取为 vertical 或 horizontal | |
bindwaiting | EventHandle | - | 视频出现缓冲时触发 |
binderror | EventHandle | - | 视频播放出错时触发 |
<video />
默认宽度 300px、高度 225px
Tip:视频格式支持mp4后缀,视频编码android支持:mediacodec_h264,h261,h263,h263p,h263i,h264,h264_vda,mpeg1video,mpeg2video,mpeg4,mpegvideo,msmpeg4v1,msmpeg4v2,msmpeg4v3,rv10,rv20,rv30,rv40,svq1,svq3,vc1,vp3,vp5,vp6,vp6a,vp6f,vp8,vp9,wmv1,wmv2,wmv3,aac,aac_latm,ac3,ac3_fixed,eac3,amrnb,amrwb,atrac1,atrac3,atrac3p,cook,mp1float,mp2float,mp3float,mp3adufloat,mp3on4float,mp1,mp2,mp2fixed,mp3,mp3adu,mp3on4,ra_144,ra_288,sipr,wmapro,wmav1,wmav2,adts,amr,asf,avi,flv,hls,matroska,mov,mp3,mpegps,mpegts,rm,rtp,rtsp,sdp,swf,aac,aac_latm,ac3,cook,h261,h263,h264,mpeg4video,mpeg4audio,mpegvideo,rv30,rv40,vc1,vp3,vp8,vp9;ios支持h264,h265。
示例:在开发者工具中预览效果
- <view class="section">
<video id="myde" src="{{src}}" controls bindplay="play" bindpause="pause" bindfullscreenchange="fullscreen" bindended="ended" autoplay="{{autoplay}}" muted="{{muted}}"></video>
</view>
<view class="btn-area">
<button bindtap="next">切换视频地址</button>
</view>
<view class="btn-area">
<button bindtap="setmuted">设置静音</button>
</view>
<view class="btn-area">
<button bindtap="setautoplay">切换 autoplay </button>
</view>
- Page({
data: {
current: 0,
srcList: ['https://vd3.bdstatic.com/mda-ia8e6q3g23py8qdh/hd/mda-ia8e6q3g23py8qdh.mp4?playlist=%5B%22hd%22%5D&auth_key=1521549485-0-0-d5d042ba3555b2d23909d16a82916ebc&bcevod_channel=searchbox_feed&pd=share', 'https://vd3.bdstatic.com/mda-ib0u8x1bvaf00qa8/mda-ib0u8x1bvaf00qa8.mp4?playlist=%5B%22hd%22%2C%22sc%22%5D'],
src: 'https://vd3.bdstatic.com/mda-ia8e6q3g23py8qdh/hd/mda-ia8e6q3g23py8qdh.mp4?playlist=%5B%22hd%22%5D&auth_key=1521549485-0-0-d5d042ba3555b2d23909d16a82916ebc&bcevod_channel=searchbox_feed&pd=share',
loop: false,
muted: false,
autoplay: false
},
play: function (e) {
console.log('play!');
},
pause: function (e) {
console.log('pause');
},
fullscreen: function (e) {
console.log('fullscreenchange!! 参数是' + JSON.stringify(e));
},
ended: function (e) {
console.log('ended');
this.next();
},
next: function (e) {
let list = this.getData('srcList');
let current = (this.getData('current') + 1) % list.length;
this.setData('src', list[current]);
this.setData('current', current);
},
setloop: function (e) {
this.setData('loop', !this.getData('loop'));
},
setmuted: function (e) {
this.setData('muted', !this.getData('muted'));
},
setautoplay: function (e) {
this.setData('autoplay', !this.getData('autoplay'));
}
});