video.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const sourceType = [['camera'], ['album'], ['camera', 'album']]
  2. const camera = [['front'], ['back'], ['front', 'back']]
  3. // eslint-disable-next-line
  4. const duration = Array.apply(null, {length: 60}).map(function (n, i) {
  5. return i + 1
  6. })
  7. Page({
  8. onShareAppMessage() {
  9. return {
  10. title: '拍摄/选择视频',
  11. path: 'page/API/pages/video/video'
  12. }
  13. },
  14. data: {
  15. sourceTypeIndex: 2,
  16. sourceType: ['拍摄', '相册', '拍摄或相册'],
  17. cameraIndex: 2,
  18. camera: ['前置', '后置', '前置或后置'],
  19. durationIndex: 59,
  20. duration: duration.map(function (t) { return t + '秒' }),
  21. src: ''
  22. },
  23. sourceTypeChange(e) {
  24. this.setData({
  25. sourceTypeIndex: e.detail.value
  26. })
  27. },
  28. cameraChange(e) {
  29. this.setData({
  30. cameraIndex: e.detail.value
  31. })
  32. },
  33. durationChange(e) {
  34. this.setData({
  35. durationIndex: e.detail.value
  36. })
  37. },
  38. chooseVideo() {
  39. const that = this
  40. wx.chooseVideo({
  41. sourceType: sourceType[this.data.sourceTypeIndex],
  42. camera: camera[this.data.cameraIndex],
  43. maxDuration: duration[this.data.durationIndex],
  44. success(res) {
  45. that.setData({
  46. src: res.tempFilePath
  47. })
  48. }
  49. })
  50. }
  51. })