2***@qq.com
2***@qq.com
  • 发布:2023-12-13 10:29
  • 更新:2023-12-13 19:58
  • 阅读:288

【报Bug】uni.getRecorderManager() 始终返回空对象

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 11 专业版

HBuilderX类型: 正式

HBuilderX版本号: 3.8.12

手机系统: Android

手机系统版本号: Android 5.0

手机厂商: 模拟器

手机机型: 华为nova

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

onLoad 执行

预期结果:

不为空对象

实际结果:

{}

bug描述:

主页通过uni.getRecorderManager() 在onLoad 获取时候返回对象都为 {} 不知道什么原因 官网的demo也不行
代码提示是有的 不知都为啥 一直返回空

升级成最新3.98 也一样 有官方解释下吗

2023-12-13 10:29 负责人:DCloud_App_Array 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

刚写了个例子,可以录音,播放

<template>  
    <view class="content">  
        <image class="logo" src="/static/logo.png" />  
        <view class="text-area">  
            <button @tap="startRecord">开始录音</button>  
            <button @tap="endRecord">停止录音</button>  
            <button @tap="playVoice">播放录音</button>  
        </view>  
    </view>  
</template>  

<script setup lang="ts">  
    import { onLoad } from '@dcloudio/uni-app'  
    import {ref} from 'vue'  
    let voicePath = ref(null)  
    let recorderManager = null  
    let innerAudioContext = null  
    onLoad(() => {  

        recorderManager = uni.getRecorderManager();  
        innerAudioContext = uni.createInnerAudioContext();  
        innerAudioContext.autoplay = true;  
        console.log('recorderManager')  
        console.log(recorderManager)  
        recorderManager.onStop(function (res) {  
            console.log('recorder stop' + JSON.stringify(res));  
            voicePath.value = res.tempFilePath  
        });  
    })  

    function startRecord() {  
        console.log('开始录音');  

        recorderManager.start();  
    }  
    function endRecord() {  
        console.log('录音结束');  
        recorderManager.stop();  
    }  
    function playVoice() {  
        console.log('播放录音');  

        if (voicePath.value) {  
            innerAudioContext.src = voicePath.value;  
            innerAudioContext.play();  
        }  
    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    .logo {  
        height: 200rpx;  
        width: 200rpx;  
        margin-top: 200rpx;  
        margin-left: auto;  
        margin-right: auto;  
        margin-bottom: 50rpx;  
    }  

    .text-area {  
        display: flex;  
        justify-content: center;  
    }  

    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>
  • DCloud_UNI_OttoJi

    不清楚是否是因为 app 权限的原因,这块是不是可以整理放入文档内,后续直接放链接就成,你熟悉这个吗

    2023-12-13 20:16

  • 喜欢技术的前端

    回复 DCloud_UNI_OttoJi: 可能不是权限的问题,先让这个用户跑一下这个例子,看功能是否正常

    2023-12-13 20:34

  • 3***@qq.com

    解决了吗

    2024-03-16 21:37

要回复问题请先登录注册