index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // components/diy-video/currentId.js
  2. Component({
  3. options: {
  4. multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  5. },
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. options: null,
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. lifetimes: {
  16. attached: function () {
  17. // 在组件实例进入页面节点树时执行
  18. this.videoContext = wx.createVideoContext("myVideo");
  19. if (this.data.autoplay) {
  20. this.setData({
  21. play: false,
  22. });
  23. }
  24. console.log(this.data.play);
  25. },
  26. detached: function () {
  27. // 在组件实例被从页面节点树移除时执行
  28. },
  29. },
  30. // 以下是旧式的定义方式,可以保持对 <2.2.3 版本基础库的兼容
  31. attached: function () {
  32. // 在组件实例进入页面节点树时执行
  33. },
  34. detached: function () {
  35. // 在组件实例被从页面节点树移除时执行
  36. },
  37. ready: function () {
  38. // 在组件布局完成后执行,确保options参数中有data信息
  39. this.loadData();
  40. },
  41. data: {
  42. style: null,
  43. vdata: null,
  44. list: [],
  45. },
  46. /**
  47. * 组件的方法列表
  48. */
  49. methods: {
  50. async loadData() {
  51. let { options } = this.data;
  52. console.log("视频组", options);
  53. let { data, style, cloumn } = options;
  54. let { src, list } = data;
  55. this.setData({
  56. list,
  57. src,
  58. style,
  59. cloumn,
  60. vdata: data,
  61. });
  62. },
  63. bindButtonTap() {
  64. const that = this;
  65. wx.chooseVideo({
  66. sourceType: ["album", "camera"],
  67. maxDuration: 60,
  68. camera: ["front", "back"],
  69. success(res) {
  70. that.setData({
  71. src: res.tempFilePath,
  72. });
  73. },
  74. });
  75. },
  76. videoTap: function (e) {
  77. //获取video
  78. let { play } = this;
  79. this.videoContext = wx.createVideoContext("myVideo", this);
  80. if (this.data.play) {
  81. //开始播放
  82. this.videoContext.play(); //开始播放
  83. this.setData({
  84. play: false,
  85. });
  86. } else {
  87. //当play==false 显示图片 暂停
  88. this.videoContext.pause(); //暂停播放
  89. this.setData({
  90. play: true,
  91. });
  92. }
  93. },
  94. bindPlayVideo() {
  95. console.log("1");
  96. this.videoContext.play();
  97. },
  98. videoErrorCallback(e) {
  99. console.log("视频错误信息:");
  100. console.log(e.detail.errMsg);
  101. },
  102. },
  103. });