video.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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: 'packageAPI/pages/media/video/video'
  12. }
  13. },
  14. data: {
  15. theme: 'light',
  16. sourceTypeIndex: 2,
  17. sourceType: ['拍摄', '相册', '拍摄或相册'],
  18. cameraIndex: 2,
  19. camera: ['前置', '后置', '前置或后置'],
  20. durationIndex: 59,
  21. duration: duration.map((t) => `${t}秒`),
  22. src: ''
  23. },
  24. sourceTypeChange(e) {
  25. this.setData({
  26. sourceTypeIndex: e.detail.value
  27. })
  28. },
  29. cameraChange(e) {
  30. this.setData({
  31. cameraIndex: e.detail.value
  32. })
  33. },
  34. durationChange(e) {
  35. this.setData({
  36. durationIndex: e.detail.value
  37. })
  38. },
  39. chooseVideo() {
  40. const that = this
  41. wx.chooseVideo({
  42. sourceType: sourceType[this.data.sourceTypeIndex],
  43. camera: camera[this.data.cameraIndex],
  44. maxDuration: duration[this.data.durationIndex],
  45. success(res) {
  46. that.setData({
  47. src: res.tempFilePath
  48. })
  49. }
  50. })
  51. },
  52. onLoad() {
  53. this.setData({
  54. theme: wx.getSystemInfoSync().theme || 'light'
  55. })
  56. if (wx.onThemeChange) {
  57. wx.onThemeChange(({theme}) => {
  58. this.setData({theme})
  59. })
  60. }
  61. }
  62. })