index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Component({
  2. behaviors: [require('../common/share-behavior').default],
  3. properties: {
  4. captureState: {
  5. type: Number,
  6. value: 0,
  7. observer: function (newVal, oldVal) {
  8. if (newVal !== oldVal) {
  9. if (newVal === 1) {
  10. this.capture();
  11. }
  12. }
  13. },
  14. },
  15. recordState: {
  16. type: Number,
  17. value: 0,
  18. observer: function (newVal, oldVal) {
  19. if (newVal !== oldVal) {
  20. if (newVal === 0) {
  21. this.recordEnd();
  22. } else {
  23. this.recordStart();
  24. }
  25. }
  26. }
  27. },
  28. captureQuality: {
  29. type: Number,
  30. value: 0.8,
  31. },
  32. captureType: {
  33. type: String,
  34. value: 'jpg',
  35. },
  36. recordFPS: {
  37. type: Number,
  38. value: 30,
  39. },
  40. recordWidth: {
  41. type: Number,
  42. value: undefined,
  43. },
  44. recordHeight: {
  45. type: Number,
  46. value: undefined,
  47. },
  48. recordBPS: {
  49. type: Number,
  50. value: 1000,
  51. },
  52. },
  53. data: {
  54. loaded: false
  55. },
  56. lifetimes: {},
  57. methods: {
  58. handleReady({detail}) {
  59. const scene = this.scene = detail.value;
  60. const appHide = () => this.scene.share.recordPause();
  61. const appShow = () => this.scene.share.recordResume();
  62. wx.onAppHide(appHide);
  63. wx.onAppShow(appShow);
  64. wx.offAppHide(appHide);
  65. wx.offAppShow(appShow);
  66. this.triggerEvent('sceneReady', {width: scene.width, height: scene.height});
  67. },
  68. capture() {
  69. this.scene.share.captureToFriends({
  70. fileType: this.data.captureType,
  71. quality: this.data.captureQuality
  72. });
  73. },
  74. recordStart() {
  75. console.log('recordStart')
  76. this.scene.share.recordStart({
  77. fps: this.data.recordFPS,
  78. videoBitsPerSecond: this.data.recordBPS,
  79. width: this.data.recordWidth,
  80. height: this.data.recordHeight
  81. });
  82. },
  83. recordEnd() {
  84. console.log('recordEnd')
  85. this.scene.share.recordFinishToAlbum();
  86. }
  87. }
  88. })