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 小时前
SAP学习笔记 - BTP SAP Build02 - Deploy,开始URL,Approve,Reject,履历确认,Log,Context
笔记·学习
zjeweler1 小时前
“网安+护网”终极300多问题面试笔记-全
笔记·网络安全·面试·职场和发展
仲芒1 小时前
[24年单独笔记] MySQL 常用的 DDL 命令
笔记·mysql·oracle
仲芒2 小时前
[24年单独笔记] MySQL 常用的 DML 命令
数据库·笔记·mysql
lwewan3 小时前
CPU 调度
笔记·考研
John.Lewis3 小时前
C++进阶(6)C++11(2)
开发语言·c++·笔记
CheerWWW4 小时前
C++学习笔记——栈内存与堆内存、宏、auto、std::array
c++·笔记·学习
-许平安-5 小时前
MCP项目笔记十(客户端 MCPClient)
c++·笔记·ai·raii·mcp·pluginapi·plugin system
一只旭宝5 小时前
【C++ 入门精讲2】函数重载、默认参数、函数指针、volatile | 手写笔记(附完整代码)
c++·笔记
John.Lewis5 小时前
C++进阶(8)智能指针
开发语言·c++·笔记