uni-app 小程序组件live-pusher无法添加autopush属性 即使添加也不会被编译

uni-app 小程序组件live-pusher无法添加autopush属性 即使添加也不会被编译

开发环境 版本号 项目创建方式
Windows win11 HBuilderX
产品分类:uniapp/小程序/微信

PC开发环境操作系统:Windows

PC开发环境操作系统版本号:win11

HBuilderX类型:正式

HBuilderX版本号:4.17

第三方开发者工具版本号:1.06.2402040

基础库版本号:2.33.0

项目创建方式:HBuilderX

### 示例代码:
```html
<view class="pusher-box">
<live-pusher
id="livePusher"
autopush="{{autopush}}"
bindstatechange="pusherstatechange"
bindnetstatus="pusherNetstatus"
enable-camera="{{enableCamera}}"
mode="{{pusherMode}}"
audio-quality="{{audioQuality}}"
min-bitrate="{{minBitrate}}"
max-bitrate="{{maxBitrate}}"
class="livePusher32"
url="{{pushUrl}}"
binderror="binderror"
style="width: 1px; height: 2px;">
</live-pusher>
</view>

操作步骤:

预期结果:

autopush属性编译后能存在

实际结果:

组件上没有autopush属性

bug描述:

某些情况下llive-push组件必须要用自动推流,就是autopush属性,但是怎么调整都无法编译出来,即使我写了个组件用纯小程序语法也不行,建议修复下


更多关于uni-app 小程序组件live-pusher无法添加autopush属性 即使添加也不会被编译的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app 小程序组件live-pusher无法添加autopush属性 即使添加也不会被编译的实战教程也可以访问 https://www.itying.com/category-93-b0.html


uni-app 中,live-pusher 是小程序原生组件,用于实时音视频推流。然而,uni-app 对小程序原生组件的支持并不是完全一致的,某些属性或功能可能无法直接使用或编译。

关于 live-pusher 组件的 autopush 属性,根据微信小程序的官方文档,live-pusher 组件确实有 autopush 属性,用于设置是否自动推流。但是,在 uni-app 中,某些原生组件的属性可能无法直接使用,或者需要特定的配置才能生效。

以下是一些可能的解决方案和注意事项:

1. 检查 uni-app 版本

确保你使用的是最新版本的 uni-app,因为新版本可能会修复一些兼容性问题。

2. 使用 custom 属性

uni-app 中,如果某个原生组件的属性不被支持,可以尝试使用 custom 属性来手动设置原生组件的属性。

<live-pusher custom="{{customProps}}"></live-pusher>
export default {
  data() {
    return {
      customProps: {
        autopush: true
      }
    }
  }
}

3. 使用 wx.createLivePusherContext

如果你发现 autopush 属性无法通过组件直接设置,可以尝试使用 wx.createLivePusherContext 来手动控制推流。

const livePusherContext = wx.createLivePusherContext('myLivePusher');

// 手动开始推流
livePusherContext.start({
  success(res) {
    console.log('推流成功', res);
  },
  fail(err) {
    console.error('推流失败', err);
  }
});

4. 检查编译配置

确保你的 manifest.jsonpages.json 中正确配置了小程序的相关设置,特别是 usingComponents 部分。

5. 直接使用原生小程序代码

如果 uni-app 的限制导致无法使用某些功能,你可以考虑直接使用原生小程序的代码来实现相关功能。

6. 反馈给 uni-app 团队

如果你确认这是一个 uni-app 的兼容性问题,可以通过 uni-app 的官方渠道(如 GitHub Issues)反馈给开发团队,以便他们修复或改进。

示例代码

以下是一个完整的示例代码,展示如何在 uni-app 中使用 live-pusher 组件并手动控制推流:

<template>
  <view>
    <live-pusher id="myLivePusher" url="rtmp://your-rtmp-url" mode="SD" :custom="customProps"></live-pusher>
    <button @tap="startPush">开始推流</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      customProps: {
        autopush: true
      }
    }
  },
  methods: {
    startPush() {
      const livePusherContext = wx.createLivePusherContext('myLivePusher');
      livePusherContext.start({
        success(res) {
          console.log('推流成功', res);
        },
        fail(err) {
          console.error('推流失败', err);
        }
      });
    }
  }
}
</script>
回到顶部