闫增涛
2024-02-23 fdfb3ca757ecd6c396632ed276ff354671d3a7e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Component({
  externalClasses: ['my-video', 'my-cover-img', 'my-play-icon'],
  properties: {
    videoSrc: { type: String },
  },
  data: {
    isShow: true,
  },
 
  options: {
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  },
 
  attached() {
    this.videoContext = wx.createVideoContext('myVideo', this);
  },
 
  fullScreen: false,
 
  methods: {
    // 点击封面自定义播放按钮时触发
    bindplay(e) {
      this.setData({
        isShow: false,
      });
      this.videoContext.play();
      this.triggerEvent('play', e);
    },
 
    bindplayByVideo(e) {
      this.setData({
        isShow: false,
      });
      this.triggerEvent('play', e);
    },
 
    // 监听播放到末尾时触发
    bindended(e) {
      if (!this.fullScreen) {
        this.setData({
          isShow: true,
        });
      }
      this.triggerEvent('ended', e);
    },
    // 监听暂停播放时触发
    bindpause(e) {
      this.triggerEvent('pause', e);
    },
    bindfullscreenchange(e) {
      const fullScreen = e?.detail?.fullScreen;
      this.fullScreen = fullScreen;
    },
  },
});