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)])

}

},

}

相关推荐
明月醉窗台31 分钟前
qt使用笔记二:main.cpp详解
数据库·笔记·qt
Shaoxi Zhang2 小时前
NVM常用命令记录
笔记
wind_one12 小时前
STM32[笔记]--1.前置准备
笔记·stm32·单片机
anyup3 小时前
快崩溃了!华为应用商店已经 4 次驳回我的应用上线
前端·华为·uni-app
jackson凌3 小时前
【Java学习笔记】String类(重点)
java·笔记·学习
a_157153249864 小时前
SpringCloud学习笔记-4
笔记·学习·spring cloud
sponge'5 小时前
opencv学习笔记2:卷积、均值滤波、中值滤波
笔记·python·opencv·学习
ljt27249606617 小时前
Compose笔记(二十六)--DatePicker
笔记·android jetpack
早日退休!!!8 小时前
性能优化笔记
笔记·性能优化
love530love8 小时前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm