index.js
2.01 KB
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
let id = 0
class videoEnPlayer extends Emitter {
constructor(options) {
super()
this.options = options.config
this.callBackFun = options.callBackFun
this.id = ++id
this.player = null
this.poster = ''
this.previewPoster = ''
this.originPoster = ''
this.isDestroy = false
this.container = document.querySelector(`#video-player-${this.options.key}`)
this.initOhtersPlayer()
this.template = new Template(this)
this.events = new Events(this)
}
get proxy() {
return this.events.proxy
}
get query() {
return this.template.query
}
initOhtersPlayer() {
const domId = this.container.getAttribute('id')
const url = this.options ? this.options.record ? this.options.record.url : '' : ''
const isDark = document.querySelector('html').getAttribute('dark-mode') === 'true'
this.originPoster = this.options.record.poster
this.previewPoster = this.options.record.poster
const cdnUrl = [
'cdnjdcontent.aikan.pdnews.cn',
'jdcontentcdn.aikan.pdnews.cn',
'sitjdcontentcdn.aikan.pdnews.cn',
'uatjdcdncollect.aikan.pdnews.cn',
'uatjdcontentcdn.aikan.pdnews.cn'
]
if (!this.previewPoster) {
this.originPoster = `${url.split('?')[0]}?x-oss-process=video/snapshot,t_0,f_jpg`
this.previewPoster = `${url.split('?')[0]}?x-oss-process=video/snapshot,t_0,f_jpg`
} else {
const isNewspaper = this.options.record.isNewspaper
this.originPoster = handleImageSrc(this.originPoster, 2, isNewspaper)
this.previewPoster = handleImageSrc(this.previewPoster, 2, isNewspaper)
}
this.poster = isDark ? './image/placeHoldVlogo.svg' : './image/placeholdLogo.svg'
this.player = new Aliplayer({
id: domId,
autoplay: this.options.isGiveWidth,
x5_type: true,
source: url
})
}
destroy() {
this.poster = ''
this.originPoster = ''
this.isDestroy = true
this.events.destroy()
if (this.player) {
this.player.dispose()
}
this.player = null
}
}