live-player.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'live-player',
  5. path: 'packageComponent/pages/media/live-player/live-player'
  6. }
  7. },
  8. data: {
  9. theme: 'light',
  10. videoSrc: ''
  11. },
  12. onReady() {
  13. this.ctx = wx.createLivePlayerContext('player')
  14. },
  15. handleScanQRCode() {
  16. wx.scanCode({
  17. complete: (res) => {
  18. const {result} = res
  19. this.setData({
  20. videoSrc: result
  21. })
  22. },
  23. })
  24. },
  25. handleLivePlayerStateChange(e) {
  26. console.log('live-player code:', e.detail.code)
  27. },
  28. handleLivePlayerError(e) {
  29. console.error('live-player error:', e.detail.errMsg)
  30. },
  31. handlePlay() {
  32. this.ctx.play({
  33. success: () => {
  34. console.log('play success')
  35. },
  36. fail: () => {
  37. console.log('play fail')
  38. }
  39. })
  40. },
  41. handlePause() {
  42. this.ctx.pause({
  43. success: () => {
  44. console.log('pause success')
  45. },
  46. fail: () => {
  47. console.log('pause fail')
  48. }
  49. })
  50. },
  51. handleStop() {
  52. this.ctx.stop({
  53. success: () => {
  54. console.log('stop success')
  55. },
  56. fail: () => {
  57. console.log('stop fail')
  58. }
  59. })
  60. },
  61. handleResume() {
  62. this.ctx.resume({
  63. success: () => {
  64. console.log('resume success')
  65. },
  66. fail: () => {
  67. console.log('resume fail')
  68. }
  69. })
  70. },
  71. handleMute() {
  72. this.ctx.mute({
  73. success: () => {
  74. console.log('mute success')
  75. },
  76. fail: () => {
  77. console.log('mute fail')
  78. }
  79. })
  80. },
  81. handleVideoSrcInput(e) {
  82. this.setData({
  83. videoSrc: e.detail.value
  84. })
  85. },
  86. onLoad() {
  87. this.setData({
  88. theme: wx.getSystemInfoSync().theme || 'light'
  89. })
  90. if (wx.onThemeChange) {
  91. wx.onThemeChange(({theme}) => {
  92. this.setData({theme})
  93. })
  94. }
  95. }
  96. })