字节跳动小程序开发API createVideoContext

2019-08-20 17:53 更新

根据video组件id创建可以控制组件的上下文VideoContext对象

参数说明


tt.createVideoContext(id, [component]);

名称 数据类型 属性 默认值 描述
id string required N/A ttml中组件的id
component object optional N/A 在自定义组件下,当前组件实例的this,以操作组件内video组件

返回值


调用后返回一个VideoContext对象,该对象包含以下方法

VideoContext.play()

播放视频

VideoContext.pause()

暂停视频

VideoContext.stop()

停止视频

VideoContext.seek(position<Number>)

视频点播,跳转到指定位置position

VideoContext.requestFullScreen()

进入全屏, 且方向固定为横屏

VideoContext.exitFullScreen()

进入全屏

代码示例



<video src="http://sf1-ttcdn-tos.pstatp.com/obj/ttfe/test/test-upload.mp4" rel="external nofollow" 
    id="myVideo" style="width: 240px; height: 180px;" controls="{{false}}"
 />

<view style="display: flex; justify-content: space-between; align-items: center;">
 <button bindtap="play" size="mini">Play</button>
 <button bindtap="pause" size="mini">Pause</button>
 <button bindtap="stop" size="mini">Stop</button>
</view>

Page({
  onReady: function () {
    this.videoCtx = tt.createVideoContext('myVideo');
  },
  play: function () {
    this.videoCtx.play();
  },
  pause: function () {
    this.videoCtx.pause()
  },
  stop: function () {
    this.videoCtx.stop()
  }
})


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号