完美解决小程序直播组件live-player全屏问题

小程序自带组件live-player并没有提供全屏按钮,需要自己手写开发 这里给大家分享一下自己的代码

遇到的坑:cover-view在安卓中不生效,可以直接用view代替  

实现思路:点击视频  显示放大图标  点击放大和缩小图标 调用对应api

代码

html

<view class="live-video" bindtap="showFull">
  <live-player id="livePlayer" src="{{liveData.pullLiveBroadcastUrl}}" mode="live" autoplay bindstatechange="statechange" catchtouchmove binderror="error">
    <view class='full_img_idv' catchtap="hideFull" wx:if="{{showControls}}">
      <view class="col-box" bindtap="unFullScreen" wx:if="{{fullScreenFlag}}">
        <image src="/images/icon/suoxiao.png" class='full_img'/>
      </view>
      <view class="col-box" wx:else bindtap="onFullScreen">
        <image src="/images/icon/fangda.png" class='full_img'/>
      </view>
    </view>
  </live-player>
</view>

css

.full_img_idv {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  background:rgba(0, 0, 0, 0.2);
}
.full_img {
  width: 20px;
  height: 20px;
  margin-right: 10rpx;
  margin-bottom: 10rpx;
}

js

hideFull() {
        this.setData({
      showControls: false
    })
  },
  onFullScreen() {
    let that = this
    this.LivePlayerContext.requestFullScreen({
      direction: 90,
      success (e) {
        that.setData({
          fullScreenFlag: true
        })
      },
      fail(e) {
        console.log(e)
      },
      complete(e) {
        console.log(e)
      }
    })
  },
  unFullScreen() {
    let that = this
    this.LivePlayerContext.exitFullScreen({
      success (e) {
        that.setData({
          fullScreenFlag: false
        })
      },
    })
  },

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值