当前位置: 首页 > news >正文

Uniapp连接iBeacon设备——实现无线定位与互动体验(实现篇)

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

http://www.lryc.cn/news/232221.html

相关文章:

  • 【ceph】ceph集群删除pool报错: “EPERM: pool deletion is disabled“
  • 【微信小程序】使用npm包
  • 【开发记录篇】第二篇:SQL创建分区表
  • vue 使用 this.$router.push 传参数,接参数的 query或params 两种方法示例
  • rk3588 usb网络共享连接
  • shell 拒绝恶意连接脚本 centos7.x拒绝恶意连接脚本
  • 【系统架构设计】计算机公共基础知识: 2 计算机系统基础知识
  • 什么是代理模式,用 Python 如何实现 Proxy(代理 或 Surrogate)对象结构型模式?
  • 国内领先的五大API接口供应商
  • 第十九章 Java绘图
  • 【C++面向对象】13. 接口 / 抽象类*
  • LeetCode热题100——二分查找
  • 使用VC++实现分段线性变换,直方图均衡化、锐化处理(使用拉普拉斯算子)
  • react class改hooks写法
  • 桂院校园导航 | 云上高校导航 云开发项目 二次开发教程 1.3
  • sscanf提取相应字符到数组
  • 本地开发环境和服务器传输数据的几种方法
  • LeetCode之二叉树
  • 论文学习——THE USTC SYSTEM FOR ADRESS-M CHALLENGE
  • 第一百七十五回 如何创建放射形状渐变背景
  • vue实现调用手机拍照、录像功能
  • WPF播放视频
  • 交换机如何配置BGP协议
  • 精通Nginx(14)-配置HTTPS
  • 封装一个简单的table组件
  • Avalonia UI框架介绍
  • 【入门篇】1.3 redis客户端之 jedis 高级使用示例
  • 使用CXF调用WSDL(二)
  • list.toArray
  • 2013年11月10日 Go生态洞察:Go语言四周年回顾