onLoad 执行
- 发布:2023-12-13 10:29
- 更新:2023-12-13 19:58
- 阅读:721
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows 11 专业版
HBuilderX类型: 正式
HBuilderX版本号: 3.8.12
手机系统: Android
手机系统版本号: Android 5.0
手机厂商: 模拟器
手机机型: 华为nova
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
不为空对象
不为空对象
实际结果:
{}
{}
喜欢技术的前端 - 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