当前位置:   article > 正文

小程序xr-frame中实现动态获取数据后vr扫描图片播放视频功能_微信小程序xr相机 扫图片出现视频

微信小程序xr相机 扫图片出现视频

示例集demo地址:木头鱼/xr-frame-demo

xr-template-tracker----------index.js文件(重点):

  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. Page({
  3. behaviors: [sceneReadyBehavior],
  4. moveTimes: 0,
  5. data: {
  6. // ...保留原有的data配置
  7. // 内置
  8. height: 100,
  9. heightScale: 1,
  10. showBackBtn: true,
  11. // 页面
  12. useScan: false,
  13. useGLTF: false,
  14. useVideo1: true,
  15. useVideo2: true,
  16. // scan 相关
  17. showMarkerWrap: false,
  18. markerLeft: -50,
  19. markerTop: 50,
  20. markerWidth: 0,
  21. markerHeight: 0,
  22. // 全局状态
  23. dataReady: false,
  24. // Debug
  25. debugMsg: 'Defalut Words',
  26. markerList: [],
  27. dataReady: false,
  28. debugMsg: 'Defalut Words',
  29. },
  30. onLoad() {
  31. this.fetchDataFromApi();
  32. },
  33. resetData() {
  34. this.setData({
  35. dataReady: false,
  36. showMarkerWrap: false,
  37. markerLeft: -50,
  38. markerTop: 50,
  39. markerWidth: 0,
  40. markerHeight: 0,
  41. })
  42. },
  43. //调取接口,获取地址数据
  44. async fetchDataFromApi() {
  45. wx.request({
  46. url: 'https://hwwym.xhtxr.com/static/video.json',
  47. method: 'GET',
  48. success: (res) => {
  49. console.log(res.data);
  50. // 处理成功响应
  51. const apiData = res.data.ar; // 假设返回的数据结构与mockDataList相似
  52. this.processFetchedData(apiData);
  53. },
  54. fail: (res) => {
  55. console.log(res);
  56. // 处理失败响应
  57. }
  58. });
  59. },
  60. processFetchedData(apiData) {
  61. // 假设apiData结构与mockDataList相同
  62. console.log(apiData);
  63. this.resetData();
  64. // 需要使用的marker
  65. const markerList = []
  66. //设置初始下标为0
  67. let videoIndex = 0
  68. //循环数据,拿到每一项数据,将对应的数据push到空数组中,接着对应下标依次添加直到找到最后一项
  69. for (let i = 0; i < apiData.length; i++) {
  70. const mockItem = apiData[i];
  71. const videoId = 'video' + videoIndex
  72. markerList.push({
  73. id: videoId,
  74. name: '音乐节',
  75. renderType: 'video',
  76. markerImage: mockItem.key,
  77. src: mockItem.val,
  78. });
  79. videoIndex++;
  80. }
  81. //最后将数据放到所需渲染的数组里面
  82. this.setData({
  83. dataReady: true,
  84. markerList: markerList,
  85. });
  86. },
  87. // ...保留原有的其他函数
  88. handleTrackerChange(cur) {
  89. const item = cur.detail;
  90. this.setData({
  91. debugMsg: 'handleTrackerChange:' + item.name
  92. })
  93. },
  94. handleTrackerMove(cur) {
  95. const detail = cur.detail
  96. const trackerInfo = detail.trackerInfo
  97. this.moveTimes++
  98. this.setData({
  99. showMarkerWrap: true,
  100. })
  101. },
  102. });

xr-template-tracker----------index.wxml文件:

  1. <view wx:if="{{dataReady}}">
  2. <xr-template-tracker
  3. disable-scroll
  4. id="main-frame"
  5. width="{{renderWidth}}"
  6. height="{{renderHeight}}"
  7. style="width:{{width}}px;height:{{height}}px;top:{{top}}px;left:{{left}}px;display:block;"
  8. markerListRaw="{{markerList}}"
  9. bindtrackerchange="handleTrackerChange"
  10. bindtrackermove="handleTrackerMove"
  11. />
  12. </view>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/833161
推荐阅读
相关标签
  

闽ICP备14008679号