uniapp音频加进度条加蓝牙ibecon设备搜索

html

<slider :value="num" :max="duration" @change="change" width="100%" :disabled="isSliderDisabled">

</slider>

js

import {

explain

} from '@/api/api.js';

export default {

data() {

return {

iBeaconDevices: \[\], // 存储搜索到的iBeacon设备

deviceId: \[\],

data: \[\],

url: getApp().globalData.url,

innerAudioContext: null,

num: 0, //秒

int: null, //定时器

duration: '111', //总时长

isSliderDisabled: false,

status: false,

audio_status: false,

type: 2

}

},

// 下拉刷新

onPullDownRefresh() {

try {

this.explain()

uni.stopPullDownRefresh(); //停止刷新

} catch (e) {}

},

onLoad() {

this.explain()

},

methods: {

play() {

if (!this.status) {

this.int = setInterval(() => {

this.num++

}, 1000)

this.status = true

this.change({

detail: {

value: this.num

}

})

} else {

this.status = false

clearInterval(this.int)

this.innerAudioContext.pause()

}

},

change(e) {

if (this.status) {

this.isSliderDisabled = true;

this.num = e.detail.value;

this.innerAudioContext.seek(e.detail.value)

setTimeout(() => {

this.innerAudioContext.play()

this.isSliderDisabled = false;

}, 500)

}

},

box(deviceid) {

console.log(deviceid, 99909);

let that = this

uni.openBluetoothAdapter({ //蓝牙初始化

success(res) {

uni.getLocation({

success(res) {

uni.startBeaconDiscovery({ //搜索蓝牙设备

uuids: deviceid,

success(res) {

console.log(res, 888);

uni.onBeaconUpdate((res) => { //监听蓝牙搜索到的设备

console.log(res, 999);

uni.hideLoading()

that.type = 1

})

},

fail(res) {

console.log('暂未搜索到蓝牙设备', res);

uni.showToast({

title: '暂未搜索到蓝牙设备,请下拉刷新',

icon: 'none'

})

}

})

},

fail(res) {

uni.showToast({

title: '请打开位置信息,并下拉刷新',

icon: 'none'

})

}

})

},

fail(res) {

console.log('蓝牙未打开', res);

uni.showToast({

title: '请打开蓝牙,并下拉刷新',

icon: 'none'

})

}

})

},

async explain() {

uni.showLoading({

title: '加载中...'

})

const res = await explain({

scenic_id: 3

})

this.data = res.data

if (!this.audio_status) {

this.innerAudioContext = uni.createInnerAudioContext()

this.innerAudioContext.src = this.url + this.data0.audio;

this.innerAudioContext.onCanplay(() => {

// 获取音频总时长,单位为秒

this.duration = this.innerAudioContext.duration

console.log('音频总时长:', this.innerAudioContext.duration, 9)

})

}

this.audio_status = true

this.box((res.data\[0.deviceid)])

}

},

}

相关推荐
Software攻城狮17 分钟前
【uniapp和普通web 端开发的区别】
前端·uni-app·notepad++
2501_9159214321 分钟前
iOS 实时日志怎么看?KeyMob 的日志过滤、崩溃报告与符号化
android·ios·小程序·https·uni-app·iphone·webview
Wanderer X35 分钟前
MiniMax-H3(ref2va)架构与推理方法笔记
笔记
深圳老胡41 分钟前
STM32C562RET6 外部中断详解:从 EXTI 原理到 GPIO 外部中断实战
笔记·stm32·单片机·代码规范·1024程序员节
海绵宝宝转agent1 小时前
leetcodehot100个人题解
java·笔记·学习·算法
李某学编程15 小时前
基于ARM的微机原理学习笔记(一)
arm开发·笔记·学习
sbjdhjd16 小时前
AI产业周度动态:从“更强模型”走向“可执行、可治理、可计价”的系统竞争 (2026年10月19日—10月25日)
人工智能·笔记·ai·开源·gemini·信息差·claude code
ss27317 小时前
AI时代首先数据库-PostgreSQL实战笔记 27 PostgreSQL数据写入与读取流程解析
数据库·笔记·postgresql
深圳老胡18 小时前
压力检测空吸功能硬件方案全解析:主流压力传感器品牌与实现路径
笔记·单片机·代码规范
程序猿追18 小时前
返回 null 不一定入队成功:鸿蒙 KMP上的并发优先队列观察笔记
笔记·华为·harmonyos·kmp