guoshilong
2023-11-13 54849757852f6ab40eb17afbd03d1d839b60a38d
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
    <div id="container" ref="container" :style="{width,height}"></div>
</template>
 
<script setup lang="ts">
import { onMounted, onUnmounted, ref, defineProps, defineEmits } from 'vue'
import Jessibuca from '../../../public/jessibuca/jessibuca'
const props = defineProps({
  videoUrl: {
    type: String,
    required: true
  },
  width: {
    type: String,
    default: '300px'
  },
  height: {
    type: String,
    default: '200px'
  }
})
const emits = defineEmits(['timeout'])
let jessibuca: null | Jessibuca = null
const container = ref(null)
const buffer = ref(null)
const showBandwidth = ref(false)
const showOperateBtns = ref(true)
const forceNoOffscreen = ref(false)
// const playUrl = ref()
const playing = ref(false)
const quieting = ref(true)
const loaded = ref(false)
const createJessibuca = () => {
  jessibuca = new (window as any).Jessibuca({
    container: container.value,
    videoBuffer: 0.2, // 缓存时长
    isResize: false,
    text: '',
    // background: "bg.jpg",
    loadingText: '加载中',
    controlAutoHide: true,
    // hasAudio:false,
    debug: true,
    showBandwidth: showBandwidth.value, // 显示网速
    operateBtns: {
      fullscreen: showOperateBtns.value,
      screenshot: showOperateBtns.value,
      play: showOperateBtns.value,
      audio: showOperateBtns.value,
    },
    forceNoOffscreen: forceNoOffscreen.value,
    isNotMute: false,
  }) as Jessibuca
 
  jessibuca.on('load', function () {
    console.log('on load')
  })
 
  jessibuca.on('log', function (msg: any) {
    console.log('on log', msg)
  })
  jessibuca.on('record', function (msg: any) {
    console.log('on record:', msg)
  })
  jessibuca.on('pause', function () {
    console.log('on pause')
    playing.value = false
  })
  jessibuca.on('play', function () {
    console.log('on play')
    playing.value = true
    loaded.value = true
    quieting.value = jessibuca?.isMute()
  })
  jessibuca.on('fullscreen', function (msg: any) {
    console.log('on fullscreen', msg)
  })
 
  jessibuca.on('mute', function (msg: any) {
    console.log('on mute', msg)
    quieting.value = msg
  })
 
  jessibuca.on('mute', function (msg: any) {
    console.log('on mute2', msg)
  })
 
  jessibuca.on('audioInfo', function (msg: any) {
    console.log('audioInfo', msg)
  })
 
  // jessibuca.on("bps", function (bps) {
  //   // console.log('bps', bps);
  // });
  // let _ts = 0;
  // jessibuca.on("timeUpdate", function (ts) {
  //   // console.log('timeUpdate,old,new,timestamp', _ts, ts, ts - _ts);
  //   // _ts = ts;
  // });
 
  jessibuca.on('videoInfo', function (info: any) {
    console.log('videoInfo', info)
  })
 
  jessibuca.on('error', function (error: any) {
    console.error('error', error)
  })
 
  jessibuca.on('timeout', function () {
    console.log('timeout')
    emits('timeout')
  })
 
  jessibuca.on('start', function () {
    console.log('start')
  })
 
  // jessibuca.on("stats", function (stats) {
  //   console.log('stats', JSON.stringify(stats));
  // });
 
  jessibuca.on('performance', function (performance: any) {
    let show = '卡顿'
    if (performance === 2) {
      show = '非常流畅'
    } else if (performance === 1) {
      show = '流畅'
    }
  })
  jessibuca.on('buffer', function (buffer: any) {
    console.log('buffer', buffer)
  })
 
  jessibuca.on('stats', function (stats: any) {
    console.log('stats', stats)
  })
 
  jessibuca.on('kBps', function (kBps: any) {
    console.log('kBps', kBps)
  })
 
  // 显示时间戳 PTS
  jessibuca.on('videoFrame', function () {
 
  })
 
  //
  jessibuca.on('metadata', function () {
 
  })
}
onMounted(() => {
  createJessibuca()
  play()
})
onUnmounted(() => {
  jessibuca && jessibuca.destroy()
})
const play = () => {
  if (props.videoUrl) {
    jessibuca?.play(props.videoUrl)
  }
}
const pause = () => {
  jessibuca?.pause()
  playing.value = false
}
 
const destroy = () => {
  if (jessibuca) {
    jessibuca.destroy()
  }
  createJessibuca()
  playing.value = false
  loaded.value = false
}
</script>
 
<style scoped lang="scss"></style>