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.data[0].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)])

}

},

}

相关推荐
繁花与尘埃1 小时前
HTML5简介与基本骨架(本文为个人学习笔记,内容整理自哔哩哔哩UP主【非学者勿扰】的公开课程。 > 所有知识点归属原作者,仅作非商业用途分享)
笔记·学习·html5
东方芷兰1 小时前
LLM 笔记 —— 04 为什么语言模型用文字接龙,图片模型不用像素接龙呢?
人工智能·笔记·深度学习·语言模型·自然语言处理
memorycx4 小时前
听课笔记CSAPP
笔记
千忧散5 小时前
Unity Socket学习笔记 (三)TCP&UDP
笔记·学习·unity·c#
今天只学一颗糖5 小时前
Linux学习笔记--触摸屏驱动
笔记·学习
Gin3876 小时前
mooc自动互评脚本笔记---2025年10月11日
笔记
蒙奇D索大7 小时前
【C语言加油站】C语言文件操作详解:从“流”的概念到文件的打开与关闭
c语言·开发语言·笔记·学习·改行学it
摇滚侠7 小时前
Spring Boot 3零基础教程,依赖管理机制,笔记06
spring boot·笔记·后端
聪明的笨猪猪7 小时前
Java Spring “事务” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
lingggggaaaa8 小时前
小迪安全学习笔记(一百零二讲)—— 漏扫项目篇&PoC开发&Yaml语法&插件一键生成&匹配结果&交互提取
笔记·学习·安全·网络安全·交互