- wx.createInnerAudioContext 在ios 手机播放 wav格式的音频无法播放?
<template> <view class="main"> <cl-card label="留言信息"> <cl-list-item label="状态" border> <cl-text type="text" :color="info.state == 1 ? '#06B27B' : '#666666'" :size="30" :value="info.state == 1 ? '已回复' : '待回复'"></cl-text> </cl-list-item> <cl-list-item label="姓名" border> <cl-text type="text" color="#666666" :size="30" :value="info.name"></cl-text> </cl-list-item> <cl-list-item label="联系电话" border> <cl-text type="text" color="#666666" :size="30" :value="info.phone"></cl-text> </cl-list-item> <cl-list-item label="留言时间" border> <cl-text type="text" color="#666666" :size="30" :value="info.createTime"></cl-text> </cl-list-item> <cl-list-item label="留言内容" border> <cl-text type="text" color="#666666" :size="26" :value="info.messageContent"></cl-text> </cl-list-item> <cl-list-item label="语音留言" border v-if="info.audioSrc"> <view> <button class="voice-btn" @click="playAudio">播放语音</button> </view> </cl-list-item> </cl-card> <view style="height: 20rpx;background: #f7f7f7;"></view> <cl-card label="回复信息" v-if="info.replyBy"> <cl-list-item label="回复人" border> <cl-text type="text" color="#666666" :size="30" :value="info.replyBy"></cl-text> </cl-list-item> <cl-list-item label="回复时间" border> <cl-text type="text" color="#666666" :size="30" :value="info.replyTime"></cl-text> </cl-list-item> <cl-list-item label="回复内容" border> <cl-text type="text" color="#666666" :size="26" :value="info.replyContent"></cl-text> </cl-list-item> <cl-list-item label="语音回复" border v-if="info.replyAudioSrc"> <view> <button class="voice-btn" @click="playReplyAudio">播放语音</button> </view> </cl-list-item> </cl-card> </view> </template> <script> export default { data() { return { info: {} } }, onLoad(options) { this.$http.post('/wechat/api/getMessageDetails', { id: options.id }).then(res => { if (res.code == 200) { this.info = res.data; } }) }, data() { return { info: {}, innerAudioContext: null, replyAudioContext: null } }, onUnload() { // 页面卸载时销毁音频上下文 if (this.innerAudioContext) { this.innerAudioContext.destroy(); } if (this.replyAudioContext) { this.replyAudioContext.destroy(); } }, methods: { // 下载音频文件并尝试播放 async downloadAndPlayAudio(url, audioContext) { return new Promise((resolve, reject) => { uni.showLoading({ title: '正在下载音频...' }); // 下载音频文件 uni.downloadFile({ url: url, success: (downloadRes) => { uni.hideLoading(); console.log('音频文件下载成功:', downloadRes); if (downloadRes.statusCode === 200) { // 尝试播放下载的音频文件 this.playDownloadedAudio(downloadRes.tempFilePath, audioContext) .then(resolve) .catch((playError) => { console.log('播放下载文件失败,尝试其他方法:', playError); // 尝试使用网络URL直接播放 this.playNetworkAudio(url, audioContext) .then(resolve) .catch(reject); }); } else { reject(new Error('下载失败')); } }, fail: (err) => { uni.hideLoading(); console.error('下载失败:', err); // 下载失败,尝试直接播放网络URL this.playNetworkAudio(url, audioContext) .then(resolve) .catch(reject); } }); }); }, // 播放下载的音频文件 playDownloadedAudio(filePath, audioContext) { return new Promise((resolve, reject) => { console.log('尝试播放下载的音频文件:', filePath); // 销毁之前的音频上下文 if (audioContext) { audioContext.destroy(); } audioContext = wx.createInnerAudioContext(); audioContext.src = filePath; audioContext.volume = 1.0; audioContext.obeyMuteSwitch = false; audioContext.onCanplay(() => { console.log('下载音频可以播放'); }); audioContext.onPlay(() => { console.log('下载音频开始播放'); uni.showToast({ title: '正在播放语音', icon: 'none' }); resolve(); }); audioContext.onError((res) => { console.error('下载音频播放错误:', res); reject(res); }); audioContext.onEnded(() => { console.log('下载音频播放结束'); uni.showToast({ title: '播放完成', icon: 'none' }); }); // 开始播放 audioContext.play(); }); }, // 播放网络音频 playNetworkAudio(url, audioContext) { return new Promise((resolve, reject) => { console.log('尝试播放网络音频:', url); // 销毁之前的音频上下文 if (audioContext) { audioContext.destroy(); } audioContext = wx.createInnerAudioContext(); audioContext.src = url; audioContext.volume = 1.0; audioContext.obeyMuteSwitch = false; audioContext.onCanplay(() => { console.log('网络音频可以播放'); }); audioContext.onPlay(() => { console.log('网络音频开始播放'); uni.showToast({ title: '正在播放语音', icon: 'none' }); resolve(); }); audioContext.onError((res) => { console.error('网络音频播放错误:', res); reject(res); }); audioContext.onEnded(() => { console.log('网络音频播放结束'); uni.showToast({ title: '播放完成', icon: 'none' }); }); // 开始播放 audioContext.play(); }); }, playAudio() { if (!this.info.audioSrc) { uni.showToast({ title: '没有语音文件', icon: 'none' }); return; } const url = `https://7519ycy.com/prod-api/file/mac/${this.info.audioSrc}`; console.log('准备播放音频URL:', url); // 下载并播放音频 this.downloadAndPlayAudio(url, this.innerAudioContext) .then(() => { console.log('音频播放成功'); }) .catch((err) => { console.error('音频播放失败:', err); uni.showToast({ title: '语音播放失败,请检查网络连接', icon: 'none' }); }); }, playReplyAudio() { if (!this.info.replyAudioSrc) { uni.showToast({ title: '没有语音文件', icon: 'none' }); return; } const url = `https://7519ycy.com/prod-api/file/mac/${this.info.replyAudioSrc}`; console.log('准备播放回复音频URL:', url); // 下载并播放音频 this.downloadAndPlayAudio(url, this.replyAudioContext) .then(() => { console.log('回复音频播放成功'); }) .catch((err) => { console.error('回复音频播放失败:', err); uni.showToast({ title: '语音播放失败,请检查网络连接', icon: 'none' }); }); } } } </script> <style> page { background: #f7f7f7; } .card { margin-top: 20rpx; } .voice-btn { background: #06b27b; color: #fff; border: none; border-radius: 20rpx; padding: 10rpx 20rpx; font-size: 26rpx; cursor: pointer; } .voice-btn:hover { background: #05a06a; } </style>
09-11 - 我的小程序为什么上线就挂了?但是从开发这工具看没问题啊,小程序有什么期限吗?
[图片][图片][图片][图片]
03-27 - 微信小程序获取wifi列表我怎么获取wifi是2.4g还是5g?
微信小程序获取wifi列表我怎么获取wifi是2.4g还是5g?类似于别人的这样的小程序,他怎么做的?[图片]
02-17 - 小程序获取附件的wifi列表数据有问题?
下面是我的代码,可以帮我看下为什么IOS的手机,我每次启动就跳到系统设置微信设置页面吗?然后我怎么才能获取这附件的wifi列表呢?下面的截图是 自动跳转到的页面。旁边是debug出来的, wx.getWifiList({ success: function (result) { this.wifiList = result.wifiList || []; console.log("获取到的 Wi-Fi 列表:", result); },这个的result结果,也没报错啊,就很奇怪 [图片][图片] wx.authorize({ scope: "scope.userLocation", success: function () { wx.startWifi({ success: function () { console.log("Wi-Fi 模块初始化成功"); wx.getWifiList({ success: function (result) { this.wifiList = result.wifiList || []; console.log("获取到的 Wi-Fi 列表:", result); }, fail: function (err) { wx.showToast({ title: "获取WiFi列表失败", err, icon: "none", }); console.error("获取 Wi-Fi 列表失败", err); }, }); }, fail: function (err) { wx.showToast({ title: "Wi-Fi 模块初始化失败", err, icon: "none", }); console.error("Wi-Fi 模块初始化失败", err); }, }); }, fail: function (err) { console.log("wifi模块初始化失败", err); // 未授权,引导用户到设置页面 wx.openSetting({ success: function (res) { if (res.authSetting["scope.userLocation"]) { // 用户授权了 Wi-Fi 权限 wx.getWifiList({ success: function (res) { console.log(res.wifiList); }, }); } }, }); }, });
01-16 - 蓝牙的问题?
我那个蓝牙相关的个人隐私设置到底成功没有呀,我都设置了好多次了,每次审核成功了,但是我也看不到到底成功了没有,我用小程序开发的时候有很多问题 不知道是不是这个影响 ,一直报错: errMsg: "openBluetoothAdapter:fail already opened" 跟 errMsg: "startBluetoothDevicesDiscovery:fail already discovering devices,但是我走错误的方法一直走蓝牙又能搜到设备 就很奇怪[图片] [图片] 补充:真机模拟的时候报错不一样:{errno: 1500101, errMsg: "startBluetoothDevicesDiscovery:fail ble adapter hans't been opened or ble is unavailable.", errCode: 10000, isDiscovering: }
01-06 - 我要用蓝牙,所以我去配置小程序用户隐私保护指引,我再进去点完善出现这个画面,这两个报红是正常的吗?
我要用蓝牙,所以我去配置小程序用户隐私保护指引,我再进去点完善出现这个画面,这两个报红是正常的吗?还是说我要去哪里解决这两个玩意[图片]
01-06 - 小程序接口设置中蓝牙设置为什么没有显示?
小程序接口设置中蓝牙开通的为什么没有[图片]
01-05