video

解释:视频

属性说明:

属性名类型默认值说明
srcString视频的资源地址
initial-timeNumber指定视频初始播放位置
durationNumber指定视频时长
controlsBooleantrue是否显示默认播放控件(播放/暂停按钮、播放进度、时间)
autoplayBooleanfalse是否自动播放
loopBooleanfalse是否循环播放
mutedBooleanfalse是否静音播放
objectFitStringcontain当视频大小与 video 容器大小不一致时,视频的表现形式。contain :包含,fill :填充,cover :覆盖
posterString-视频封面的图片网络资源地址
page-gestureBooleanfalse在非全屏模式下,是否开启使用手势调节亮度与音量。
show-progressBooleantrue若不设置,宽度大于240时才会显示。
show-fullscreen-btnBooleantrue是否显示全屏按钮
enable-progress-gestureBooleantrue是否开启使用手势控制进度
danmu-listArray.<object>-弹幕列表
danmu-btnBooleanfalse是否显示弹幕按钮,只在初始化时有效,不能动态变更。
enable-danmuBooleanfalse是否展示弹幕,只在初始化时有效,不能动态变更。
show-play-btnBooleantrue是否显示视频底部控制栏的播放按钮
show-center-play-btnBooleantrue是否显示视频中间的播放按钮
bindpauseEventHandle当暂停播放时触发 pause 事件
bindendedEventHandle当播放到末尾时触发 ended 事件
bindtimeupdateEventHandle播放进度变化时触发,event.detail = {currentTime, duration} 。
bindfullscreenchangeEventHandle当视频进入和退出全屏是触发,event.detail = {fullscreen, direction},direction 取为 vertical 或 horizontal
bindwaitingEventHandle-视频出现缓冲时触发
binderrorEventHandle-视频播放出错时触发

<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。

示例:在开发者工具中预览效果

  1. <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>

  1. 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'));
    }
    });