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

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.kler.cn/news/135795.html

相关文章:

  • 基础组件-流量回放(全链路流量回放预研)
  • 论文-分布式-拜占庭将军问题
  • 免疫微环境、免疫细胞浸润分析、免疫功能分析
  • 解决在pycharm中使用matplotlib画图问题
  • SpringBean的配置详解 --中
  • UnitTest框架
  • 图像处理01 小波变换
  • uni-app开发微信小程序 vue3写法添加pinia
  • 云桌面 node_modules 切换艰辛历程记录 rebuild失败记录
  • Positive Technologies 利用 PT Cloud Application Firewall 保护中小型企业的网络资源
  • (八)、基于 LangChain 实现大模型应用程序开发 | 基于知识库的个性化问答 (检索 Retrieval)
  • 实用篇-ES-RestClient查询文档
  • 使用Lychee搭建个人图片存储系统并进行远程访问设置实现公网访问本地私人图床
  • 拼图游游戏代码
  • Vatee万腾携手Wiki EXPO 2023悉尼峰会 共谱辉煌未来
  • Java code auditing
  • 力扣刷题-二叉树-完全二叉树的节点个数
  • Go 语言中的map和内存泄漏
  • 【GitLab】-HTTP 500 curl 22 The requested URL returned error: 500~SSH解决
  • 界面组件DevExpress Reporting v23.1亮点 - 全新升级报表查看器
  • 立哥先进技术-常用渗透测试工具
  • Workplace Search 的演变:使用 Elasticsearch 搜索你的私人数据
  • 细说MySQL数据类型
  • 安装R和Rstudio
  • 庖丁解牛:NIO核心概念与机制详解 06 _ 连网和异步 I/O
  • uniapp如何上传文件,使用API是什么
  • 贪吃蛇代码
  • JVM的运行时数据区
  • 算法学习 day26
  • SQL零基础入门教程,贼拉详细!贼拉简单! 速通数据库期末考!(九)