开发
API

LivePlayerContext

LivePlayerContext 通过 id 跟一个直播组件 <live-player /> 绑定,操作对应的直播组件。

方法

播放

livePlayerContext.play()

停止

livePlayerContext.stop()

静音

livePlayerContext.mute()

取消静音

livePlayerContext.unmute()

进入全屏

livePlayerContext.requestFullScreen(options)

参数 options

属性名类型默认值必填说明最低支持版本
directionnumber0用来控制进入全屏时画面朝向1.44.0
direction 取值范围
direction 值说明
0默认是 0,正常竖向
90屏幕逆时针 90 度
-90屏幕顺时针 90 度

退出全屏

livePlayerContext.exitFullScreen()

代码示例

<live-player
  id="my-player"
  src="https://pull-flv-l6.ixigua.com/game/stream-106078795436654621.flv"
  bindstatechange="statechange"
>
  <button bindtap="play" size="mini" hidden="{{isFullscreen}}">播放</button>

  <button bindtap="stop" size="mini" hidden="{{!isFullscreen}}">停止</button>

  <button bindtap="mute" size="mini" hidden="{{!isFullscreen}}">静音</button>

  <button bindtap="unmute" size="mini" hidden="{{!isFullscreen}}">取消静音</button>

  <button bindtap="requestFullScreen" size="mini" hidden="{{isFullscreen}}">进入全屏</button>

  <button bindtap="exitFullScreen" size="mini" hidden="{{!isFullscreen}}">退出全屏</button>
</live-player>
Page({
  livePlayerContext: undefined,

  // 创建 context
  onReady() {
    this.livePlayerContext = tt.createLivePlayerContext("my-player");
  },

  // 监听状态变化
  statechange(event) {
    console.log("状态变化", event);
  },

  // 播放
  play() {
    this.livePlayerContext.play();
  },

  // 停止
  stop() {
    this.livePlayerContext.stop();
  },

  // 静音
  mute() {
    this.livePlayerContext.mute();
  },

  // 取消静音
  unmute() {
    this.livePlayerContext.unmute();
  },

  // 进入全屏
  requestFullScreen() {
    this.livePlayerContext.requestFullScreen({
      direction: 0,
    });
  },

  // 退出全屏
  exitFullScreen() {
    this.livePlayerContext.exitFullScreen();
  },
});

Bug & Tip

点击纠错
评价此篇文档